[Borges-users] a unit test?
Слепнев Владимир
slepnev_v at rambler.ru
Sun May 2 15:43:17 EDT 2004
Hi,
it seems that documenting the system with unit tests is really the way
to go. Here's something I just wrote, and I'm really proud of it:
require 'test/unit'
module Borges; end
class Borges::StateHolder # mock
attr_accessor :contents
def initialize(*args)
end
end
require 'Borges/Controller/Controller'
require 'Borges/Utilities/RenderNotification'
class ControllerTest < Test::Unit::TestCase
# one Controller may 'call' another. this must raise a
RenderNotification.
# when the called controller invokes 'answer', the original 'call'
# must return the value passed to 'answer'.
def test_answer
@c1 = Borges::Controller.new
@c2 = Borges::Controller.new
moment = 0
assert_raises(Borges::RenderNotification) do
assert_equal "yeah we've done it", @c1.call(@c2)
raise Borges::RenderNotification.new if moment==1
end
if(moment==0) then
moment = 1
@c2.answer "yeah we've done it"
end
end
end
Ah yes, do you mind my using a tab instead of two spaces? It seems
much more natural to me, because editors can adjust the tab width. (XP
coding standards, anyone? =) And am I on the right track with all
this?
Vladimir Slepnev
More information about the Borges-users
mailing list