From 13058b018861053be8bf5dbec4cafe51b89e173f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20L=C3=BCtke?= Date: Fri, 1 Jun 2007 20:20:19 +0000 Subject: 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 --- .../lib/active_support/core_ext/test/difference.rb | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'activesupport/lib') 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 -- cgit v1.2.3