Permalink
Browse files

fixing assert_difference issues on ruby 1.8

  • Loading branch information...
1 parent 19ab8e4 commit 2d2c9179adcd64e2125ea49d5d9517985bbccb01 @tenderlove tenderlove committed Aug 4, 2011
Showing with 7 additions and 6 deletions.
  1. +7 −6 activesupport/lib/active_support/testing/assertions.rb
View
13 activesupport/lib/active_support/testing/assertions.rb
@@ -45,18 +45,19 @@ module Assertions
# post :delete, :id => ...
# end
def assert_difference(expression, difference = 1, message = nil, &block)
- exps = Array.wrap(expression).map { |e|
- callee = e.respond_to?(:call) ? e : lambda { eval(e, block.binding) }
- [e, callee]
+ expressions = Array.wrap expression
+
+ exps = expressions.map { |e|
+ e.respond_to?(:call) ? e : lambda { eval(e, block.binding) }
}
- before = exps.map { |_, block| block.call }
+ before = exps.map { |e| e.call }
yield
- exps.each_with_index do |(code, block), i|
+ expressions.zip(exps).each_with_index do |(code, e), i|
error = "#{code.inspect} didn't change by #{difference}"
error = "#{message}.\n#{error}" if message
- assert_equal(before[i] + difference, block.call, error)
+ assert_equal(before[i] + difference, e.call, error)
end
end

0 comments on commit 2d2c917

Please sign in to comment.