Skip to content

Commit

Permalink
Add helper method install test
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Mar 30, 2024
1 parent 9c868d2 commit 9cfb4fd
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/irb/test_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,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",
"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_workspace_stack_when_no_arg_is_given
Expand Down Expand Up @@ -1001,4 +1015,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

0 comments on commit 9cfb4fd

Please sign in to comment.