aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/test/difference.rb2
-rw-r--r--activesupport/test/test_test.rb7
2 files changed, 8 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/test/difference.rb b/activesupport/lib/active_support/core_ext/test/difference.rb
index 7b22b32d26..17cac8919d 100644
--- a/activesupport/lib/active_support/core_ext/test/difference.rb
+++ b/activesupport/lib/active_support/core_ext/test/difference.rb
@@ -20,7 +20,7 @@ module Test #:nodoc:
# post :delete, :id => ...
# end
def assert_difference(expression, difference = 1, &block)
- expression_evaluation = lambda { eval(expression) }
+ expression_evaluation = lambda { eval(expression, block.binding) }
original_value = expression_evaluation.call
yield
assert_equal original_value + difference, expression_evaluation.call
diff --git a/activesupport/test/test_test.rb b/activesupport/test/test_test.rb
index d8a02b5497..e29534ccaf 100644
--- a/activesupport/test/test_test.rb
+++ b/activesupport/test/test_test.rb
@@ -46,4 +46,11 @@ class AssertDifferenceTest < Test::Unit::TestCase
@object.decrement
end
end
+
+ def test_expression_is_evaluated_in_the_appropriate_scope
+ local_scope = 'foo'
+ assert_difference 'local_scope; @object.num' do
+ @object.increment
+ end
+ end
end