Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit f7bd676c8d2fab1b22ede4e12242b37eb3336884 1 parent 187e1f8
Tobias Lütke authored
Showing with 16 additions and 4 deletions.
  1. +16 −4 activesupport/lib/active_support/core_ext/test/difference.rb
View
20 activesupport/lib/active_support/core_ext/test/difference.rb
@@ -25,13 +25,19 @@ class TestCase #: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 @@ def assert_difference(expressions, difference = 1, &block)
# 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
Please sign in to comment.
Something went wrong with that request. Please try again.