diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-08-03 16:55:00 -0700 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2011-08-13 16:22:28 -0700 |
commit | eaee18dd9abe6a72e83743009931f7765a005f24 (patch) | |
tree | 394ce3856453c962c6eff9ba9cc6db89fe05db04 /activesupport/lib/active_support/testing/assertions.rb | |
parent | bb72183bca60c105c901f6c38cf81dae3a104102 (diff) | |
download | rails-eaee18dd9abe6a72e83743009931f7765a005f24.tar.gz rails-eaee18dd9abe6a72e83743009931f7765a005f24.tar.bz2 rails-eaee18dd9abe6a72e83743009931f7765a005f24.zip |
make assert_difference error message not suck
Diffstat (limited to 'activesupport/lib/active_support/testing/assertions.rb')
-rw-r--r-- | activesupport/lib/active_support/testing/assertions.rb | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/testing/assertions.rb b/activesupport/lib/active_support/testing/assertions.rb index 3864b1f5a6..ba34e9853c 100644 --- a/activesupport/lib/active_support/testing/assertions.rb +++ b/activesupport/lib/active_support/testing/assertions.rb @@ -46,16 +46,17 @@ module ActiveSupport # end def assert_difference(expression, difference = 1, message = nil, &block) exps = Array.wrap(expression).map { |e| - e.respond_to?(:call) ? e : lambda { eval(e, block.binding) } + callee = e.respond_to?(:call) ? e : lambda { eval(e, block.binding) } + [e, callee] } - before = exps.map { |e| e.call } + before = exps.map { |_, block| block.call } yield - exps.each_with_index do |e, i| - error = "#{e.inspect} didn't change by #{difference}" + exps.each_with_index do |(code, block), i| + error = "#{code.inspect} didn't change by #{difference}" error = "#{message}.\n#{error}" if message - assert_equal(before[i] + difference, e.call, error) + assert_equal(before[i] + difference, block.call, error) end end |