@@ -490,6 +490,118 @@ def show_source_test_method
490490 end
491491 end
492492
493+ class WorkspaceCommandTestCase < CommandTestCase
494+ def setup
495+ super
496+ # create Foo under the test class's namespace so it doesn't pollute global namespace
497+ self . class . class_eval <<~RUBY
498+ class Foo; end
499+ RUBY
500+ end
501+ end
502+
503+ class CwwsTest < WorkspaceCommandTestCase
504+ def test_cwws_returns_the_current_workspace_object
505+ out , err = execute_lines (
506+ "cwws.class" ,
507+ )
508+
509+ assert_empty err
510+ assert_include ( out , self . class . name )
511+ end
512+ end
513+
514+ class PushwsTest < WorkspaceCommandTestCase
515+ def test_pushws_switches_to_new_workspace_and_pushes_the_current_one_to_the_stack
516+ out , err = execute_lines (
517+ "pushws #{ self . class } ::Foo.new\n " ,
518+ "cwws.class" ,
519+ )
520+ assert_empty err
521+ assert_include ( out , "#{ self . class } ::Foo" )
522+ end
523+
524+ def test_pushws_extends_the_new_workspace_with_command_bundle
525+ out , err = execute_lines (
526+ "pushws Object.new\n " ,
527+ "self.singleton_class.ancestors"
528+ )
529+ assert_empty err
530+ assert_include ( out , "IRB::ExtendCommandBundle" )
531+ end
532+
533+ def test_pushws_prints_help_message_when_no_arg_is_given
534+ out , err = execute_lines (
535+ "pushws\n " ,
536+ )
537+ assert_empty err
538+ assert_match ( /No other workspace/ , out )
539+ end
540+ end
541+
542+ class WorkspacesTest < WorkspaceCommandTestCase
543+ def test_workspaces_returns_the_array_of_non_main_workspaces
544+ out , err = execute_lines (
545+ "pushws #{ self . class } ::Foo.new\n " ,
546+ "workspaces.map { |w| w.class.name }" ,
547+ )
548+
549+ assert_empty err
550+ # self.class::Foo would be the current workspace
551+ # self.class would be the old workspace that's pushed to the stack
552+ assert_include ( out , "=> [\" #{ self . class } \" ]" )
553+ end
554+
555+ def test_workspaces_returns_empty_array_when_no_workspaces_were_added
556+ out , err = execute_lines (
557+ "workspaces.map(&:to_s)" ,
558+ )
559+
560+ assert_empty err
561+ assert_include ( out , "=> []" )
562+ end
563+ end
564+
565+ class PopwsTest < WorkspaceCommandTestCase
566+ def test_popws_replaces_the_current_workspace_with_the_previous_one
567+ out , err = execute_lines (
568+ "pushws Foo.new\n " ,
569+ "popws\n " ,
570+ "cwws.class" ,
571+ )
572+ assert_empty err
573+ assert_include ( out , "=> #{ self . class } " )
574+ end
575+
576+ def test_popws_prints_help_message_if_the_workspace_is_empty
577+ out , err = execute_lines (
578+ "popws\n " ,
579+ )
580+ assert_empty err
581+ assert_match ( /workspace stack empty/ , out )
582+ end
583+ end
584+
585+ class ChwsTest < WorkspaceCommandTestCase
586+ def test_chws_replaces_the_current_workspace
587+ out , err = execute_lines (
588+ "chws #{ self . class } ::Foo.new\n " ,
589+ "cwws.class" ,
590+ )
591+ assert_empty err
592+ assert_include ( out , "=> #{ self . class } ::Foo" )
593+ end
594+
595+ def test_chws_does_nothing_when_receiving_no_argument
596+ out , err = execute_lines (
597+ "chws\n " ,
598+ "cwws.class" ,
599+ )
600+ assert_empty err
601+ assert_include ( out , "=> #{ self . class } " )
602+ end
603+ end
604+
493605 class WhereamiTest < CommandTestCase
494606 def test_whereami
495607 out , err = execute_lines (
0 commit comments