diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2009-02-06 09:55:18 -0800 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-02-06 09:55:32 -0800 |
commit | 7564d98929af0bb039cb10c59dff6d177c11bd13 (patch) | |
tree | bcf0987ad0807c2385d1434d51dee2e5b9e5db1f /activesupport/lib/active_support | |
parent | 8746f7cac2d9bd92f91f7371a6f6b3487bae7a3b (diff) | |
download | rails-7564d98929af0bb039cb10c59dff6d177c11bd13.tar.gz rails-7564d98929af0bb039cb10c59dff6d177c11bd13.tar.bz2 rails-7564d98929af0bb039cb10c59dff6d177c11bd13.zip |
Include failed difference expression in assert message
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/testing/assertions.rb | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/activesupport/lib/active_support/testing/assertions.rb b/activesupport/lib/active_support/testing/assertions.rb index 7b19e3f35f..771c116dff 100644 --- a/activesupport/lib/active_support/testing/assertions.rb +++ b/activesupport/lib/active_support/testing/assertions.rb @@ -31,16 +31,18 @@ module ActiveSupport # assert_difference 'Article.count', -1, "An Article should be destroyed" do # post :delete, :id => ... # end - def assert_difference(expressions, difference = 1, message = nil, &block) - case expressions + def assert_difference(expression, difference = 1, message = nil, &block) + case expression when String - before = eval(expressions, block.send(:binding)) + before = eval(expression, block.send(:binding)) yield - assert_equal(before + difference, eval(expressions, block.send(:binding)), message) + error = "#{expression.inspect} didn't change by #{difference}" + error = "#{message}.\n#{error}" if message + assert_equal(before + difference, eval(expression, block.send(:binding)), error) when Enumerable - expressions.each { |e| assert_difference(e, difference, message, &block) } + expression.each { |e| assert_difference(e, difference, message, &block) } else - raise ArgumentError, "Unrecognized expression: #{expressions.inspect}" + raise ArgumentError, "Unrecognized expression: #{expression.inspect}" end end @@ -56,8 +58,8 @@ module ActiveSupport # assert_no_difference 'Article.count', "An Article should not be destroyed" do # post :create, :article => invalid_attributes # end - def assert_no_difference(expressions, message = nil, &block) - assert_difference expressions, 0, message, &block + def assert_no_difference(expression, message = nil, &block) + assert_difference expression, 0, message, &block end end end |