aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activesupport/lib/active_support/testing/assertions.rb18
-rw-r--r--activesupport/test/test_test.rb7
2 files changed, 15 insertions, 10 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
diff --git a/activesupport/test/test_test.rb b/activesupport/test/test_test.rb
index 298037e27c..d250b10822 100644
--- a/activesupport/test/test_test.rb
+++ b/activesupport/test/test_test.rb
@@ -66,7 +66,8 @@ class AssertDifferenceTest < ActiveSupport::TestCase
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 @@ class AssertDifferenceTest < ActiveSupport::TestCase
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