test/spy/test_subroutine.rb in spy-1.0.3 vs test/spy/test_subroutine.rb in spy-1.0.4

- old
+ new

@@ -148,10 +148,18 @@ string end assert_equal string, result end + def test_spy_and_call_through_with_hash_and_keyword_args + spy_on(@pen, 'hash_and_keyword_arg').and_call_through + hsh = { hello: 'world' } + + assert_equal [hsh, nil], @pen.hash_and_keyword_arg(hsh) + assert_equal [hsh, 'foo'], @pen.hash_and_keyword_arg(hsh, keyword: 'foo') + end + def test_spy_and_call_through_returns_original_method_result string = "hello world" write_spy = spy_on(@pen, :write).and_call_through another_spy = spy_on(@pen, :another).and_call_through @@ -233,9 +241,23 @@ assert pen_write_spy.has_been_called_with?("hello") @pen.write("world") assert pen_write_spy.has_been_called_with?("hello") @pen.write("hello world") assert pen_write_spy.has_been_called_with?("hello") + end + + def test_has_been_called_with_kwargs + pen_write_spy = spy_on(@pen, :opt_kwargs) + refute pen_write_spy.has_been_called_with?("hello") + + @pen.opt_kwargs("hello") + assert pen_write_spy.has_been_called_with?("hello") + + @pen.opt_kwargs("world", opt: "hello") + assert pen_write_spy.has_been_called_with?("world", opt: "hello") + + @pen.opt_kwargs("hello world", opt: "world", opt2: "hello") + assert pen_write_spy.has_been_called_with?("hello world", opt: "world", opt2: "hello") end def test_spy_hook_records_number_of_calls2 args = ["hello world"] block = Proc.new {}