test/spy/test_subroutine.rb in spy-0.4.5 vs test/spy/test_subroutine.rb in spy-1.0.0

- old
+ new

@@ -38,17 +38,17 @@ another_spy.unhook assert_equal "another", Pen.another end def test_spy_can_hook_and_record_a_meta_method_call_on_a_constant - assert_equal "meta_method", Pen.meta_method - meta_spy = spy_on(Pen, :meta_method) + assert_equal "meta_class_method", Pen.meta_class_method + meta_spy = spy_on(Pen, :meta_class_method) refute meta_spy.has_been_called? - assert_nil Pen.meta_method + assert_nil Pen.meta_class_method assert meta_spy.has_been_called? meta_spy.unhook - assert_equal "meta_method", Pen.meta_method + assert_equal "meta_class_method", Pen.meta_class_method end def test_spy_can_hook_record_and_unhook_a_meta_method assert_equal "meta_method", @pen.meta_method meta_spy = spy_on(@pen, :meta_method) @@ -194,9 +194,41 @@ assert_raises ArgumentError do @pen.greet end assert_raises ArgumentError do @pen.greet("hello", "bob", "error") + end + end + + def test_that_method_spy_keeps_arity_with_optional_keyword_args + spy_on(@pen, :opt_kwargs) + @pen.opt_kwargs(:pos1) + @pen.opt_kwargs(:pos1, opt: 1, opt2: 2) + assert_raises ArgumentError do + @pen.opt_kwargs + end + assert_raises ArgumentError do + @pen.opt_kwargs(:pos1, :pos2, opt: 1) + end + end + + def test_that_method_spy_keeps_arity_with_keyword_splat + spy_on(@pen, :keyrest) + @pen.keyrest + @pen.keyrest(a: 1, b: 2) + assert_raises ArgumentError do + @pen.keyrest(:pos1, :pos2) + end + end + + def test_that_method_spy_keeps_arity_with_required_keyword_args + spy_on(@pen, :req_kwargs) + @pen.req_kwargs(req1: 1, req2: 2) + assert_raises ArgumentError do + @pen.req_kwargs + end + assert_raises ArgumentError do + @pen.req_kwargs(:pos1, :pos2) end end def test_hook_mimics_public_visibility spy_on(@pen, :public_method)