require File.join(File.dirname(__FILE__), 'spartan_helper') require 'active_test/asserts/difference' class TestObject attr_accessor :id, :title, :count def initialize(count = 0) self.count = count self.title = "I am a Test Object" end def remove(amount = 1) self.count -= amount end def add(amount = 1) self.count += amount end def update_title self.title.reverse! end def self.count ObjectSpace.each_object(TestObject) { } end end class AssertsDifferenceTest < Test::Unit::TestCase include ActiveTest::Asserts::Difference def setup @object = TestObject.new end def test_should_assert_difference_of_one assert_difference TestObject, :count do TestObject.new end end def test_should_assert_no_difference assert_no_difference @object, :count do end end def test_should_assert_difference_greater_than_one assert_difference @object, :count, 1068 do @object.add 1068 end end def test_should_assert_difference_on_floats assert_difference @object, :count, 0.5 do @object.add 0.5 end end def test_should_assert_negative_difference_of_one assert_difference @object, :count, -1 do @object.remove end end def test_should_assert_change_in_return_value assert_change @object, :title do @object.update_title end end def test_should_assert_change_with_duping assert_change @object, :title do @object.title = "jimminy cricket" end end def test_should_assert_no_change assert_no_change @object, :count do @object.update_title end end end