1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

convert strings to lambdas so we can use a consistent interface to the objects in the collection

This commit is contained in:
Aaron Patterson 2011-05-01 12:16:12 -07:00
parent 23eb81a3d1
commit b8ccd05524

View file

@ -45,17 +45,17 @@ module ActiveSupport
# post :delete, :id => ... # post :delete, :id => ...
# end # end
def assert_difference(expression, difference = 1, message = nil, &block) def assert_difference(expression, difference = 1, message = nil, &block)
b = block.send(:binding) exps = Array.wrap(expression).map { |e|
exps = Array.wrap(expression) e.respond_to?(:call) ? e : lambda { eval(e, block.binding) }
before = exps.map { |e| e.respond_to?(:call) ? e.call : eval(e, b) } }
before = exps.map { |e| e.call }
yield yield
exps.each_with_index do |e, i| exps.each_with_index do |e, i|
error = "#{e.inspect} didn't change by #{difference}" error = "#{e.inspect} didn't change by #{difference}"
error = "#{message}.\n#{error}" if message error = "#{message}.\n#{error}" if message
actual = e.respond_to?(:call) ? e.call : eval(e, b) assert_equal(before[i] + difference, e.call, error)
assert_equal(before[i] + difference, actual, error)
end end
end end