Testing library code

Hi,

Just a quick question: If one creates custom classes and modules and
places them in the lib/ folder of rails, where should the tests for
those classes/modules go? Are they just unit tests?

Thanks,
Toby

[email protected] wrote:

Hi,

Just a quick question: If one creates custom classes and modules and
places them in the lib/ folder of rails, where should the tests for
those classes/modules go? Are they just unit tests?

Thanks,
Toby

Well it is just ruby code so you can make a small ruby application and
test it that way, and you can do it with test too I presume.

What I mean is that I would like to use test::unit to test my modules
and classes but I’m not sure where to put the test I write in the
directory structure of rails. Some of my controllers rely on these
modules/classes so they require testing, I’m just not sure how to go
about it.

I tend to think of them as part of my unit tests
(that is the way they generally get used)

If you want to put in a bit of work, you could very easily add a
/test/lib directory
and define a “test:libs” rake command.

namespace :test do
Rake::TestTask.new(:libs => “db:test:prepare”) do |t|
t.libs << “test”
t.pattern = ‘test/lib/**/*_test.rb’
t.verbose = true
end
Rake::Task[‘test:libs’].comment = “Run the lib tests in test/lib”
end

stick that in a file in lib/tasks

you’d then want to overwrite the default test task, like so…

desc ‘Test all units and functionals’
task :test do
exceptions = [“test:units”, “test:libs”, “test:functionals”,
“test:integration”].collect do |task|
begin
Rake::Task[task].invoke
nil
rescue => e
e
end
end.compact

exceptions.each {|e| puts e;puts e.backtrace }
raise “Test failures” unless exceptions.empty?
end

(note: all of the code above is made from just small changes to the
default tasks, found inside the rails gem –
/rails/lib/tasks/testing.rake

[email protected] wrote:

What I mean is that I would like to use test::unit to test my modules
and classes but I’m not sure where to put the test I write in the
directory structure of rails. Some of my controllers rely on these
modules/classes so they require testing, I’m just not sure how to go
about it.

[email protected] wrote:

What I mean is that I would like to use test::unit to test my modules
and classes but I’m not sure where to put the test I write in the
directory structure of rails. Some of my controllers rely on these
modules/classes so they require testing, I’m just not sure how to go
about it.

Put all unit-level tests in test/unit.

The meaning of “unit test” isn’t “model test”; it’s generally the
low-level
tests.

If you don’t want to run too many tests between each edit, google for
“test:svn_modified” and use that to trigger only the tests files you
changed
since your last integration.


Phlip
http://www.oreilly.com/catalog/9780596510657/
“Test Driven Ajax (on Rails)”
assert_xpath, assert_javascript, & assert_ajax