Unit tests and checking libraries

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 M.
07739 171 531
MSc (DIC)

Timezone: GMT

john maclean wrote:

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.