mirror of https://github.com/rails/rails
Evaluate expression for assert_difference in the scope of the block
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6701 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
388f504f6d
commit
2b6ad48ea3
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue