testing shared behaviors

0 views
Skip to first unread message

Semin Lee

unread,
Apr 8, 2008, 6:56:41 AM4/8/08
to shoulda
Hi guys,

I was wondering if there is an easy to do some tests on shared
behaviors using Shoulda (or test:unit). I am extracting shared methods
(or behaviors) out of individual classes and make them as a separate
module to be shared, but I don't find an easy and DRY way to test this
shared behaviors.

Rspec seems to provide this kind of functionality by using external
shared_examples (http://rspec.info/examples.html), but I don't want to
switch back to Rspec because I am already addicted to Shoulda's
terseness. :)

What do you guys think about this? Any suggestions?

Cheers,
Semin

david.l...@gmail.com

unread,
Apr 8, 2008, 1:48:28 PM4/8/08
to sho...@googlegroups.com
Hi Semin,
I'm not sure if I understand exactly what you're asking, but I
think you could just write a test to test your module methods (which I
assume you are mixing into a class by the include keyword?)
If you need to test it in the context of a class, just create a dummy
class which mixes in your module:

class Foo; include MyModule; end

class MyModuleTest < Test::Unit::TestCase

context "An instance of a class with MyModule methods mixed-in" do
setup do
@object = Foo.new
end

should "do some stuff" do
assert @object
end
end

end

-David

Semin Lee

unread,
Apr 9, 2008, 4:22:45 PM4/9/08
to sho...@googlegroups.com
Hi David,

Thank you for your suggestion. That's a good idea!

Cheers,
Semin

Reply all
Reply to author
Forward
0 new messages