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:
parent
23eb81a3d1
commit
b8ccd05524
1 changed files with 5 additions and 5 deletions
|
@ -45,17 +45,17 @@ module ActiveSupport
|
|||
# post :delete, :id => ...
|
||||
# end
|
||||
def assert_difference(expression, difference = 1, message = nil, &block)
|
||||
b = block.send(:binding)
|
||||
exps = Array.wrap(expression)
|
||||
before = exps.map { |e| e.respond_to?(:call) ? e.call : eval(e, b) }
|
||||
exps = Array.wrap(expression).map { |e|
|
||||
e.respond_to?(:call) ? e : lambda { eval(e, block.binding) }
|
||||
}
|
||||
before = exps.map { |e| e.call }
|
||||
|
||||
yield
|
||||
|
||||
exps.each_with_index do |e, i|
|
||||
error = "#{e.inspect} didn't change by #{difference}"
|
||||
error = "#{message}.\n#{error}" if message
|
||||
actual = e.respond_to?(:call) ? e.call : eval(e, b)
|
||||
assert_equal(before[i] + difference, actual, error)
|
||||
assert_equal(before[i] + difference, e.call, error)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue