diff options
Diffstat (limited to 'activesupport/lib/active_support/testing')
-rw-r--r-- | activesupport/lib/active_support/testing/assertions.rb | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/testing/assertions.rb b/activesupport/lib/active_support/testing/assertions.rb index ce2f44efd6..7b19e3f35f 100644 --- a/activesupport/lib/active_support/testing/assertions.rb +++ b/activesupport/lib/active_support/testing/assertions.rb @@ -32,12 +32,15 @@ module ActiveSupport # post :delete, :id => ... # end def assert_difference(expressions, difference = 1, message = nil, &block) - expression_evaluations = Array(expressions).collect{ |expression| lambda { eval(expression, block.send(:binding)) } } - - original_values = expression_evaluations.inject([]) { |memo, expression| memo << expression.call } - yield - expression_evaluations.each_with_index do |expression, i| - assert_equal original_values[i] + difference, expression.call, message + case expressions + when String + before = eval(expressions, block.send(:binding)) + yield + assert_equal(before + difference, eval(expressions, block.send(:binding)), message) + when Enumerable + expressions.each { |e| assert_difference(e, difference, message, &block) } + else + raise ArgumentError, "Unrecognized expression: #{expressions.inspect}" end end |