diff options
author | madlep <madlep@ubercharged.net> | 2008-10-03 11:58:28 +1000 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2008-10-03 21:31:56 +0200 |
commit | 00e2ba76b21d3c433a0ecda0de28d931c34d1791 (patch) | |
tree | e6af86c9303af0ae08e1c59b90ecf2b1c5d14d2d /activesupport/lib/active_support/testing/core_ext/test/unit/assertions.rb | |
parent | 395369bc2b85346e8f196f202941e5015dc1481e (diff) | |
download | rails-00e2ba76b21d3c433a0ecda0de28d931c34d1791.tar.gz rails-00e2ba76b21d3c433a0ecda0de28d931c34d1791.tar.bz2 rails-00e2ba76b21d3c433a0ecda0de28d931c34d1791.zip |
added nicer failure reporting to #assert_difference to tell you the expression that failed rather than just the expected and actual values
Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#1161 state:committed]
Diffstat (limited to 'activesupport/lib/active_support/testing/core_ext/test/unit/assertions.rb')
-rw-r--r-- | activesupport/lib/active_support/testing/core_ext/test/unit/assertions.rb | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/testing/core_ext/test/unit/assertions.rb b/activesupport/lib/active_support/testing/core_ext/test/unit/assertions.rb index 63d1ba6507..e5853bf828 100644 --- a/activesupport/lib/active_support/testing/core_ext/test/unit/assertions.rb +++ b/activesupport/lib/active_support/testing/core_ext/test/unit/assertions.rb @@ -37,15 +37,18 @@ module Test # end def assert_difference(expressions, difference = 1, message = nil, &block) expression_evaluations = Array(expressions).map do |expression| - lambda do + [expression, lambda do eval(expression, block.__send__(:binding)) - end + end] end - original_values = expression_evaluations.inject([]) { |memo, expression| memo << expression.call } + original_values = expression_evaluations.inject([]) { |memo, expression| memo << expression[1].call } yield expression_evaluations.each_with_index do |expression, i| - assert_equal original_values[i] + difference, expression.call, message + full_message = "" + full_message << "#{message}.\n" if message + full_message << "<#{expression[0]}> was the expression that failed" + assert_equal original_values[i] + difference, expression[1].call, full_message end end |