Modules and TestUnit

D

Daniel Berger

Hi all,

If I have a module, and I want to test that module's methods
independently within TestUnit, what is the best approach?

Am I obligated to define module_function for each method so that I can
do assert_equal("foo",MyModule.foo)? Or am I just supposed to
"include" the module in the subclass of Test::Unit::TestCase and use
it that way?

Advice appreciated.

Dan
 
D

David Heinemeier Hansson

Am I obligated to define module_function for each method so that I can
do assert_equal("foo",MyModule.foo)? Or am I just supposed to
"include" the module in the subclass of Test::Unit::TestCase and use
it that way?

I've done the latter with much success. Unless your module modifies the
class in some way that interferes with the test case running, you
should be all good.
 
N

Nathaniel Talbott

I've done the latter with much success. Unless your module modifies
the class in some way that interferes with the test case running, you
should be all good.

If the module does interfere with tests running, it's pretty easy to
just do:

class ModuleContainer
include MyModule
end

def setup
@module = ModuleContainer.new
end

But including it right in the TestCase is obviously a bit simpler.


Nathaniel
Terralien, Inc.

<:((><
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top