From b8ccd0552473fbe0f346334e37b7d84481dd3533 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sun, 1 May 2011 12:16:12 -0700 Subject: [PATCH] convert strings to lambdas so we can use a consistent interface to the objects in the collection --- activesupport/lib/active_support/testing/assertions.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/activesupport/lib/active_support/testing/assertions.rb b/activesupport/lib/active_support/testing/assertions.rb index bfc2024529..05da50e150 100644 --- a/activesupport/lib/active_support/testing/assertions.rb +++ b/activesupport/lib/active_support/testing/assertions.rb @@ -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