aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorTobias Lütke <tobias.luetke@gmail.com>2007-07-09 22:10:34 +0000
committerTobias Lütke <tobias.luetke@gmail.com>2007-07-09 22:10:34 +0000
commitf7bd676c8d2fab1b22ede4e12242b37eb3336884 (patch)
tree761c031ba6df0f5fb725122241d94ac0e87199aa /activesupport
parent187e1f85d0c871ba61e5bc3651a7ec2f657db8f9 (diff)
downloadrails-f7bd676c8d2fab1b22ede4e12242b37eb3336884.tar.gz
rails-f7bd676c8d2fab1b22ede4e12242b37eb3336884.tar.bz2
rails-f7bd676c8d2fab1b22ede4e12242b37eb3336884.zip
Allow for optional messages on assert_difference [nicwilliams] Closes #8928
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7174 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/test/difference.rb20
1 files changed, 16 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/core_ext/test/difference.rb b/activesupport/lib/active_support/core_ext/test/difference.rb
index 05eab30603..d2c81d97c0 100644
--- a/activesupport/lib/active_support/core_ext/test/difference.rb
+++ b/activesupport/lib/active_support/core_ext/test/difference.rb
@@ -25,13 +25,19 @@ module Test #:nodoc:
# assert_difference [ 'Article.count', 'Post.count' ], +2 do
# post :create, :article => {...}
# end
- def assert_difference(expressions, difference = 1, &block)
+ #
+ # A error message can be specified.
+ #
+ # assert_difference 'Article.count', -1, "An Article should be destroyed" do
+ # post :delete, :id => ...
+ # end
+ def assert_difference(expressions, difference = 1, message = nil, &block)
expression_evaluations = [expressions].flatten.collect{|expression| lambda { eval(expression, block.binding) } }
original_values = expression_evaluations.inject([]) { |memo, expression| memo << expression.call }
yield
expression_evaluations.each_with_index do |expression, i|
- assert_equal original_values[i] + difference, expression.call
+ assert_equal original_values[i] + difference, expression.call, message
end
end
@@ -41,8 +47,14 @@ module Test #:nodoc:
# assert_no_difference 'Article.count' do
# post :create, :article => invalid_attributes
# end
- def assert_no_difference(expressions, &block)
- assert_difference expressions, 0, &block
+ #
+ # A error message can be specified.
+ #
+ # 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
end
end
end