Permalink
Browse files

convert strings to lambdas so we can use a consistent interface to th…

…e objects in the collection
  • Loading branch information...
tenderlove committed May 1, 2011
1 parent 23eb81a commit b8ccd0552473fbe0f346334e37b7d84481dd3533
Showing with 5 additions and 5 deletions.
  1. +5 −5 activesupport/lib/active_support/testing/assertions.rb
@@ -45,17 +45,17 @@ module Assertions
# 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

0 comments on commit b8ccd05

Please sign in to comment.