Unit tests and checking libraries

J

john maclean

You've writen some code and it works. You now begin to think of the
future and how it might scale/grow/bloat. You think that it's a good
time to introduce Test::Unit into the mix. You write a test to ensure
that a library has been required. You check this test by adding a
/dummy/ library that does /not/ exist and the test shows no errors.

How to test that a script has loaded library foo?


=begin
How to test that a script has loaded library foo?
=end

require 'test/unit'
require '/path/to/code.rb'

# test to check that library has been required.

class PathNameHiddenTest < Test::Unit::TestCase
def test_libraries
message = "library not loaded"
assert $".grep(/foo.rb/)
end
end



--
John Maclean
07739 171 531
MSc (DIC)

Timezone: GMT
 
P

Phlip

john said:
You've writen some code and it works. You now begin to think of the
future and how it might scale/grow/bloat. You think that it's a good
time to introduce Test::Unit into the mix.

Use Test Driven Development. Don't write any code - to begin with - until you
write a failing test.

The test does not give two craps if you require this or that library. It only
cares that the work got done. You can refactor - even replace the library - and
the tests will still pass.

All the sing-song you hear on these forums about Cucumber, BDD, shoulda, Rails
integration tests, etc. - all of that works downstream from the assumption that
tests are leading your development.
 

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
473,773
Messages
2,569,594
Members
45,125
Latest member
VinayKumar Nevatia_
Top