Skip to content

Commit

Permalink
fixing assert_difference issues on ruby 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Aug 4, 2011
1 parent 19ab8e4 commit 2d2c917
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions activesupport/lib/active_support/testing/assertions.rb
Expand Up @@ -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

Expand Down

0 comments on commit 2d2c917

Please sign in to comment.