[Borges-users] a unit test?
wilkes joiner
wilkesjoiner at gmail.com
Sun May 2 20:40:36 EDT 2004
After playing around with Borges for the past week, and having played
with Seaside a year or so ago, it would be shame for it to not be as
rock solid as possible. As a HUGE fan of unit test, it is encouraging
to see this issue being addressed.
Here is a similiar test of the of Controller#call. It checks each of
the 3 conditional branches of the method.
==BEGIN==
<pre>
require 'test/unit'
require 'Borges'
module Borges; end
class Borges::StateHolder # mock
attr_accessor :contents
def initialize(*args)
end
end
class Borges::Controller
attr_reader :continuation
end
class ControllerTest < Test::Unit::TestCase
def test_PassesControl
c1 = Borges::Controller.new
c2 = Borges::Controller.new
class << c2
def call(c = nil)
true
end
end
assert c1.call(c2)
end
def test_CallSelfSaveContinuation
c1 = Borges::Controller.new
assert c1.continuation.nil?
assert_raises(Borges::RenderNotification) { c1.call }
assert !c1.continuation.nil?, "continuation should be saved"
end
def test_CallSelfDoNotSaveContinuation
c1 = Borges::Controller.new
class << c1
def will_answer?
false
end
end
assert c1.continuation.nil?
assert_raises(Borges::RenderNotification) { c1.call }
assert c1.continuation.nil?, "continuation should not be saved"
end
end
</pre>
==END==
On Sun, 02 May 2004 23:43:17 +0400, Слепнев Владимир
<slepnev_v at rambler.ru> wrote:
>
> 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
> --
> Borges-users mailing list
> http://borges.rubyforge.org/ - Borges-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/borges-users
>
More information about the Borges-users
mailing list