From 689b529ea82b2375ee3f743eb82da9b83e0d00ff Mon Sep 17 00:00:00 2001 From: Marcel Molina Date: Tue, 8 May 2007 03:54:34 +0000 Subject: Simplify API of assert_difference by passing in an expression that is evaluated before and after the passed in block. See documenation for examples of new API. [Marcel Molina Jr.] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6693 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/test/test_test.rb | 47 +++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 16 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/test_test.rb b/activesupport/test/test_test.rb index 63a44e9379..d8a02b5497 100644 --- a/activesupport/test/test_test.rb +++ b/activesupport/test/test_test.rb @@ -3,32 +3,47 @@ require File.dirname(__FILE__) + '/abstract_unit' class AssertDifferenceTest < Test::Unit::TestCase def setup - @object = Class.new { attr_accessor :num }.new + @object = Class.new do + attr_accessor :num + def increment + self.num += 1 + end + + def decrement + self.num -= 1 + end + end.new + @object.num = 0 end def test_assert_no_difference - @object.num = 0 - - assert_no_difference @object, :num do + assert_no_difference '@object.num' do # ... end - end + def test_assert_difference - @object.num = 0 - - - assert_difference @object, :num, +1 do - @object.num = 1 + assert_difference '@object.num', +1 do + @object.increment end - end - def test_methods_available - - assert self.respond_to?(:assert_difference) - assert self.respond_to?(:assert_no_difference) - + def test_assert_difference_with_implicit_difference + assert_difference '@object.num' do + @object.increment + end end + def test_arbitrary_expression + assert_difference '@object.num + 1', +2 do + @object.increment + @object.increment + end + end + + def test_negative_differences + assert_difference '@object.num', -1 do + @object.decrement + end + end end -- cgit v1.2.3