From c6e4fffa5f4d016cf34307513fcc532fc42d3fd9 Mon Sep 17 00:00:00 2001 From: tompng Date: Thu, 22 Feb 2024 23:57:18 +0900 Subject: [PATCH] Add helper method install test --- test/irb/test_command.rb | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/irb/test_command.rb b/test/irb/test_command.rb index ddcfc7c0d..9c70d1377 100644 --- a/test/irb/test_command.rb +++ b/test/irb/test_command.rb @@ -548,12 +548,26 @@ def test_pushws_switches_to_new_workspace_and_pushes_the_current_one_to_the_stac end def test_pushws_extends_the_new_workspace_with_command_bundle + IRB::ExtendCommandBundle.module_eval do + def foobar; end + end out, err = execute_lines( "pushws Object.new\n", "self.singleton_class.ancestors" ) assert_empty err assert_include(out, "IRB::ExtendCommandBundle") + ensure + IRB::ExtendCommandBundle.remove_method :foobar + end + + def test_pushws_does_not_extend_command_bundle_by_default + out, err = execute_lines( + "pushws Object.new\n", + "self.singleton_class.ancestors" + ) + assert_empty err + assert_not_include(out, "IRB::ExtendCommandBundle") end def test_pushws_prints_help_message_when_no_arg_is_given @@ -995,4 +1009,28 @@ def test_history_grep end + class HelperMethodInsallTest < CommandTestCase + def test_extend_command_bundle_not_installed_by_default + out, err = execute_lines("self.singleton_class.ancestors") + assert_empty err + assert_not_include(out, 'IRB::ExtendCommandBundle') + end + + def test_helper_method_install + IRB::ExtendCommandBundle.module_eval do + def foobar + "test_helper_method_foobar" + end + end + out, err = execute_lines("self.singleton_class.ancestors") + assert_empty err + assert_include(out, "IRB::ExtendCommandBundle") + + out, err = execute_lines("foobar.upcase") + assert_empty err + assert_include(out, '=> "TEST_HELPER_METHOD_FOOBAR"') + ensure + IRB::ExtendCommandBundle.remove_method :foobar + end + end end