Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

make assert_difference error message not suck

  • Loading branch information...
commit e63d3f7a917e78fb3a5b5098518817afe21baead 1 parent c1b85ed
@tenderlove tenderlove authored
Showing with 6 additions and 5 deletions.
  1. +6 −5 activesupport/lib/active_support/testing/assertions.rb
View
11 activesupport/lib/active_support/testing/assertions.rb
@@ -46,16 +46,17 @@ module Assertions
# end
def assert_difference(expression, difference = 1, message = nil, &block)
exps = Array.wrap(expression).map { |e|
- e.respond_to?(:call) ? e : lambda { eval(e, block.binding) }
+ callee = e.respond_to?(:call) ? e : lambda { eval(e, block.binding) }
+ [e, callee]
}
- before = exps.map { |e| e.call }
+ before = exps.map { |_, block| block.call }
yield
- exps.each_with_index do |e, i|
- error = "#{e.inspect} didn't change by #{difference}"
+ exps.each_with_index do |(code, block), i|
+ error = "#{code.inspect} didn't change by #{difference}"
error = "#{message}.\n#{error}" if message
- assert_equal(before[i] + difference, e.call, error)
+ assert_equal(before[i] + difference, block.call, error)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.