Browse files

Oops, don't yield per expression

  • Loading branch information...
1 parent 49afe58 commit 24ac1d6bdc860d234e70dd4cd4713bd13ac9d40d @jeremy jeremy committed Feb 6, 2009
Showing with 9 additions and 10 deletions.
  1. +9 −10 activesupport/lib/active_support/testing/assertions.rb
View
19 activesupport/lib/active_support/testing/assertions.rb
@@ -32,17 +32,16 @@ module Assertions
# post :delete, :id => ...
# end
def assert_difference(expression, difference = 1, message = nil, &block)
- case expression
- when String
- before = eval(expression, block.send(:binding))
- yield
- error = "#{expression.inspect} didn't change by #{difference}"
+ b = block.send(:binding)
+ exps = Array.wrap(expression)
+ before = exps.map { |e| eval(e, b) }
+
+ yield
+
+ exps.each_with_index do |e, i|
+ error = "#{e.inspect} didn't change by #{difference}"
error = "#{message}.\n#{error}" if message
- assert_equal(before + difference, eval(expression, block.send(:binding)), error)
- when Enumerable
- expression.each { |e| assert_difference(e, difference, message, &block) }
- else
- raise ArgumentError, "Unrecognized expression: #{expression.inspect}"
+ assert_equal(before[i] + difference, eval(e, b), error)
end
end

0 comments on commit 24ac1d6

Please sign in to comment.