aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext
diff options
context:
space:
mode:
authorTobias Lütke <tobias.luetke@gmail.com>2007-06-01 20:20:19 +0000
committerTobias Lütke <tobias.luetke@gmail.com>2007-06-01 20:20:19 +0000
commit13058b018861053be8bf5dbec4cafe51b89e173f (patch)
tree8042495855f9ba31d192eba869307b4624772a9b /activesupport/lib/active_support/core_ext
parent4d1c87a069d0e13347f28ff9ce4db2427efe18b1 (diff)
downloadrails-13058b018861053be8bf5dbec4cafe51b89e173f.tar.gz
rails-13058b018861053be8bf5dbec4cafe51b89e173f.tar.bz2
rails-13058b018861053be8bf5dbec4cafe51b89e173f.zip
Enhance assert_difference to accept arrays of strings which are then evaled
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6926 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/core_ext')
-rw-r--r--activesupport/lib/active_support/core_ext/test/difference.rb21
1 files changed, 15 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/core_ext/test/difference.rb b/activesupport/lib/active_support/core_ext/test/difference.rb
index 17cac8919d..05eab30603 100644
--- a/activesupport/lib/active_support/core_ext/test/difference.rb
+++ b/activesupport/lib/active_support/core_ext/test/difference.rb
@@ -19,11 +19,20 @@ module Test #:nodoc:
# assert_difference 'Article.count', -1 do
# post :delete, :id => ...
# end
- def assert_difference(expression, difference = 1, &block)
- expression_evaluation = lambda { eval(expression, block.binding) }
- original_value = expression_evaluation.call
+ #
+ # An array of expressions can also be passed in and evaluated.
+ #
+ # assert_difference [ 'Article.count', 'Post.count' ], +2 do
+ # post :create, :article => {...}
+ # end
+ def assert_difference(expressions, difference = 1, &block)
+ expression_evaluations = [expressions].flatten.collect{|expression| lambda { eval(expression, block.binding) } }
+
+ original_values = expression_evaluations.inject([]) { |memo, expression| memo << expression.call }
yield
- assert_equal original_value + difference, expression_evaluation.call
+ expression_evaluations.each_with_index do |expression, i|
+ assert_equal original_values[i] + difference, expression.call
+ end
end
# Assertion that the numeric result of evaluating an expression is not changed before and after
@@ -32,8 +41,8 @@ module Test #:nodoc:
# assert_no_difference 'Article.count' do
# post :create, :article => invalid_attributes
# end
- def assert_no_difference(expression, &block)
- assert_difference expression, 0, &block
+ def assert_no_difference(expressions, &block)
+ assert_difference expressions, 0, &block
end
end
end