aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib')
-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