From: Wayne Blair Date: 2001-05-18T06:41:24+09:00 Subject: [ruby-talk:15347] Re: help with rubyunit Hi Max, Here is the solution to the problem, finally. I looked into the source and it appears that the framework is setting up the tests so that a prepared result and the result are observing each other. These objects do not know about the class you are testing as needing observing. This is the override of setup_assert that runit TestCase uses internally to notify the observers when an assert is run. Instead of including RUNIT::Assert in the tested class, pass a reference to the test class into the verify method and call it back to assert and the asserts will be counted: class MockNoteHandler # do not include assert def initialize subscribeForNotes(self) end def onNewNote(sender, event, data) @actual_sender = sender @actual_data = data end def expectData(sender, data) @sender = sender @data = data end def verify(testCase) testCase.assert(@actual_data == @data) testCase.assert(@actual_sender == @sender) end end class NotterTest < RUNIT::TestCase include Notter def setup @mh = MockNoteHandler.new end def test_simple_note assert_exception(RuntimeError) { note() } @mh.expectData('NotterTest', 'greets') note 'greets' @mh.verify(self) # pass reference to self end end if $0 == __FILE__ require 'runit/cui/testrunner' RUNIT::CUI::TestRunner.run(NotterTest.suite) end "Max Ischenko" wrote in message news:d870e9.9jt.ln@barloo.malva.com.ua... > > Hello. I'm writing unit test with rubyunit and have a problem. > > As you can see from the snapshot below, I run NotterTest.suite > Problem is that it calls MockNoteHandler#verify which does actual > asserts, but those asserts are not counted. > > $ runtest.rb tests/notter.rb > > NotterTest#test_simple_note "NotterTest" > . > Time: 0.001849 > OK (1/1 tests 1 asserts) > > > How can count those asserts in MockNoteHandler class? > > > class MockNoteHandler > include RUNIT::Assert > > def initialize > subscribeForNotes(self) > end > > def onNewNote(sender, event, data) > @actual_sender = sender > @actual_data = data > end > > def expectData(sender, data) > @sender = sender > @data = data > end > > def verify > assert(@actual_data == @data) > assert(@actual_sender == @sender) > end > end > > class NotterTest < RUNIT::TestCase > include Notter > > def setup > @mh = MockNoteHandler.new > end > > def test_simple_note > assert_exception(RuntimeError) { note() } > @mh.expectData('NotterTest', 'greets') > note 'greets' > @mh.verify > end > end > > if $0 == __FILE__ > require 'runit/cui/testrunner' > RUNIT::CUI::TestRunner.run(NotterTest.suite) > end > > > -- > BOFH excuse #439: > Hot Java has gone cold