diff options
Diffstat (limited to 'activesupport/lib/active_support/testing/assertions.rb')
-rw-r--r-- | activesupport/lib/active_support/testing/assertions.rb | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/testing/assertions.rb b/activesupport/lib/active_support/testing/assertions.rb index 05da50e150..f3629ada5b 100644 --- a/activesupport/lib/active_support/testing/assertions.rb +++ b/activesupport/lib/active_support/testing/assertions.rb @@ -45,15 +45,17 @@ module ActiveSupport # post :delete, :id => ... # end def assert_difference(expression, difference = 1, message = nil, &block) - exps = Array.wrap(expression).map { |e| + expressions = Array.wrap expression + + exps = expressions.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}" + expressions.zip(exps).each_with_index do |(code, e), i| + error = "#{code.inspect} didn't change by #{difference}" error = "#{message}.\n#{error}" if message assert_equal(before[i] + difference, e.call, error) end @@ -68,7 +70,7 @@ module ActiveSupport # # A error message can be specified. # - # assert_no_difference 'Article.count', "An Article should not be destroyed" do + # assert_no_difference 'Article.count', "An Article should not be created" do # post :create, :article => invalid_attributes # end def assert_no_difference(expression, message = nil, &block) |