diff options
author | Marcel Molina <marcel@vernix.org> | 2007-05-08 03:54:34 +0000 |
---|---|---|
committer | Marcel Molina <marcel@vernix.org> | 2007-05-08 03:54:34 +0000 |
commit | 689b529ea82b2375ee3f743eb82da9b83e0d00ff (patch) | |
tree | aeb4d5f7ba1e546bcdadc1fa1b09ea4fdc5c8eb9 /activesupport/test | |
parent | c7befb896e72e6087d2d413990d319c990154c7e (diff) | |
download | rails-689b529ea82b2375ee3f743eb82da9b83e0d00ff.tar.gz rails-689b529ea82b2375ee3f743eb82da9b83e0d00ff.tar.bz2 rails-689b529ea82b2375ee3f743eb82da9b83e0d00ff.zip |
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
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/test_test.rb | 47 |
1 files changed, 31 insertions, 16 deletions
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 |