>The assert method in Test::Unit::Assertions is different from the 
>assert method in Test::Unit::TestCase in one way: it is not included in 
>the total count.

>I am wondering if something like the following might not work for you. 
>If it does, let us know.

>Bret

Hi. Many thanks for the tool! I preciate it much, and write here first
time, because
I have some ideas and questions on the subject.

To be included in the test case's count the class should call its
"add_assertion".
As the "assert" method itself calls its virtual "add_assertion", now I use
this kind of a mixin:

module TestManager
        include Test::Unit::Assertions

        def add_assertion
                @currentCase.send :add_assertion
        end

        def assertions_bind_to(testCase)
                @bindStack = Array.new unless @bindStack
                @bindStack.push @currentCase if @currentCase
                @currentCase = testCase
        end

        def assertions_unbind_from(testCase)
                raise "No binds were made" unless @currentCase
                raise ArgumentError.new(
                        "Last bind was to [EMAIL PROTECTED] not to
#{testCase}"
                                           ) unless @currentCase ==
testCase

                @currentCase = @bindStack.pop
        end
end


That is the way I use it:

require 'TestManager'

class UserManager
        include TestManager

        def login
                .
                assert is_logged_in
        end

        .
end


And that is the test case will look like:

class TC_User < Test::Unit::TestCase

  def test_scenario
        user = UserManager.new
        user.assertions_bind_to self

        .
  end


  # I use setup and teardown methods to bind global asserting utilities.
  def setup
        TestApplication.assertions_bind_to self
  end

  def teardown
        TestApplication.assertions_unbind_from self
  end
end


But I still wonder if it could be done more elegant. For instance, I would
like to use reflection in the TestManager, to define the test case it was
called from. Still I am not aware it is possible.


Yury

_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to