Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Include failed difference expression in assert message

  • Loading branch information...
commit 7564d98929af0bb039cb10c59dff6d177c11bd13 1 parent 8746f7c
@jeremy jeremy authored
View
18 activesupport/lib/active_support/testing/assertions.rb
@@ -31,16 +31,18 @@ module Assertions
# 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 @@ def assert_difference(expressions, difference = 1, message = nil, &block)
# 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
View
7 activesupport/test/test_test.rb
@@ -66,7 +66,8 @@ def test_array_of_expressions_identify_failure
end
fail 'should not get to here'
rescue Exception => e
- assert_equal "<3> expected but was\n<2>.", e.message
+ assert_match(/didn't change by/, e.message)
+ assert_match(/expected but was/, e.message)
end
def test_array_of_expressions_identify_failure_when_message_provided
@@ -75,7 +76,9 @@ def test_array_of_expressions_identify_failure_when_message_provided
end
fail 'should not get to here'
rescue Exception => e
- assert_equal "something went wrong.\n<3> expected but was\n<2>.", e.message
+ assert_match(/something went wrong/, e.message)
+ assert_match(/didn't change by/, e.message)
+ assert_match(/expected but was/, e.message)
end
else
def default_test; end
Please sign in to comment.
Something went wrong with that request. Please try again.