test/spy/test_subroutine.rb in spy-0.2.1 vs test/spy/test_subroutine.rb in spy-0.2.2
- old
+ new
@@ -72,12 +72,11 @@
spy.hook
end
end
def test_spy_can_hook_a_non_existent_method_if_param_set
- spy = Subroutine.new(@pen, :no_method).and_return(:yep)
- spy.hook(force: true)
+ Subroutine.new(@pen, :no_method).hook(force:true).and_return(:yep)
assert_equal :yep, @pen.no_method
end
def test_spy_and_return_returns_the_set_value
result = "hello world"
@@ -186,25 +185,40 @@
end
def test_hook_mimics_public_visibility
spy_on(@pen, :public_method)
assert @pen.singleton_class.public_method_defined? :public_method
- refute @pen.singleton_class.protected_method_defined? :public_method
- refute @pen.singleton_class.private_method_defined? :public_method
end
def test_hook_mimics_protected_visibility
spy_on(@pen, :protected_method)
- refute @pen.singleton_class.public_method_defined? :protected_method
assert @pen.singleton_class.protected_method_defined? :protected_method
- refute @pen.singleton_class.private_method_defined? :protected_method
end
def test_hook_mimics_private_visibility
spy_on(@pen, :private_method)
- refute @pen.singleton_class.public_method_defined? :private_method
- refute @pen.singleton_class.protected_method_defined? :private_method
assert @pen.singleton_class.private_method_defined? :private_method
+ end
+
+ def test_hook_mimics_class_public_visibility
+ spy_on(Pen, :public_method)
+ assert Pen.public_method_defined? :public_method
+ Spy.off(Pen, :public_method)
+ assert Pen.public_method_defined? :public_method
+ end
+
+ def test_hook_mimics_class_protected_visibility
+ spy_on(Pen, :protected_method)
+ assert Pen.protected_method_defined? :protected_method
+ Spy.off(Pen, :protected_method)
+ assert Pen.protected_method_defined? :protected_method
+ end
+
+ def test_hook_mimics_class_private_visibility
+ spy_on(Pen, :private_method)
+ assert Pen.private_method_defined? :private_method
+ Spy.off(Pen, :private_method)
+ assert Pen.private_method_defined? :private_method
end
def test_spy_get_can_retrieve_a_spy
pen_write_spy = spy_on(@pen, :write).and_return(:hello)
assert_equal :hello, @pen.write(:world)