Forum: Ruby Unit tests and checking libraries

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Acd90f2627e42cf3727fed4dfb347c1e?d=identicon&s=25 john maclean (Guest)
on 2009-03-08 18:27
(Received via mailing list)
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
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-03-08 18:41
(Received via mailing list)
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.
This topic is locked and can not be replied to.