Skip to content
Browse files

Fix for Ruby 1.9.2.

It appears that it is no longer possible to subvert the protection
of a method by calling it via send in Ruby 1.9.2.
  • Loading branch information...
1 parent 5e96208 commit c5736db505cab18dc646d40a670213f7d3be5fbe @floehopper floehopper committed May 11, 2010
View
5 test/acceptance/stub_any_instance_method_test.rb
@@ -47,13 +47,16 @@ def my_instance_method
:original_return_value
end
protected :my_instance_method
+ def my_unprotected_instance_method
+ my_instance_method
+ end
end
instance = klass.new
run_as_test do
klass.any_instance.stubs(:my_instance_method).returns(:new_return_value)
end
assert instance.protected_methods(false).any? { |m| m.to_s == 'my_instance_method' }
- assert_equal :original_return_value, instance.send(:my_instance_method)
+ assert_equal :original_return_value, instance.my_unprotected_instance_method
end
def test_should_leave_stubbed_private_method_unchanged_after_test
View
5 test/acceptance/stub_class_method_test.rb
@@ -50,13 +50,16 @@ def my_class_method
:original_return_value
end
protected :my_class_method
+ def my_unprotected_class_method
+ my_class_method
+ end
end
end
run_as_test do
klass.stubs(:my_class_method).returns(:new_return_value)
end
assert klass.protected_methods(false).any? { |m| m.to_s == 'my_class_method' }
- assert_equal :original_return_value, klass.send(:my_class_method)
+ assert_equal :original_return_value, klass.my_unprotected_class_method
end
def test_should_leave_stubbed_private_method_unchanged_after_test
View
5 test/acceptance/stub_instance_method_test.rb
@@ -32,12 +32,15 @@ def my_instance_method
:original_return_value
end
protected :my_instance_method
+ def my_unprotected_instance_method
+ my_instance_method
+ end
end.new
run_as_test do
instance.stubs(:my_instance_method).returns(:new_return_value)
end
assert instance.protected_methods(false).any? { |m| m.to_s == 'my_instance_method' }
- assert_equal :original_return_value, instance.send(:my_instance_method)
+ assert_equal :original_return_value, instance.my_unprotected_instance_method
end
def test_should_leave_stubbed_private_method_unchanged_after_test
View
4 test/acceptance/stub_module_method_test.rb
@@ -32,12 +32,12 @@ def test_should_leave_stubbed_public_method_unchanged_after_test
end
def test_should_leave_stubbed_protected_method_unchanged_after_test
- mod = Module.new { class << self; def my_module_method; :original_return_value; end; protected :my_module_method; end }
+ mod = Module.new { class << self; def my_module_method; :original_return_value; end; protected :my_module_method; def my_unprotected_module_method; my_module_method; end; end }
run_as_test do
mod.stubs(:my_module_method).returns(:new_return_value)
end
assert mod.protected_methods(false).any? { |m| m.to_s == 'my_module_method' }
- assert_equal :original_return_value, mod.send(:my_module_method)
+ assert_equal :original_return_value, mod.my_unprotected_module_method
end
def test_should_leave_stubbed_private_method_unchanged_after_test

0 comments on commit c5736db

Please sign in to comment.
Something went wrong with that request. Please try again.