"Max Ischenko" <max / malva.com.ua> 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

RUnit counts tests, not assertions.  The framework creates a test for each
noarg method starting with 'test_' in your test case class.  Each of those
tests is counted (not individual assertions, put multiple assertions in
:test_simple_note and you'll see that the entire method counted as one
test.)  So, while the assertions in aMockNoteHandler.verify would cause the
only test, :test_simple_note, to fail, it all still only counts as one test,
even if those assertions pass.  If you want them to count as separate tests,
make a one to one relationship between each :test_method in NotterTest and
:someInstanceMethod with a single assert in MockNoteHandler.

Wayne