Test::Spec released
Posted by rue, Fri Sep 29 21:49:00 UTC 2006
Christian Neukirchen (chris2) just released Test::Spec, an implementation of BDD leveraging the existing standard library Test::Unit framework (RSpec is the canonical BDD framework but it is dependent on RubyGems and, to me, seems a bit overengineered). Christian was also kind—or lazy—enough to include my should_output implementation, too!
Get the most recent version from http://chneukirchen.org/releases.
The implementation is a very slick hundred-or-so lines but the real beauty of it is that it works essentially with just a require 'test/spec' at the top of the file; you can also freely intersperse old-style Test::Unit tests and assertions with the new ones.
Translation from RSpec is simple: Test::Spec uses the “Magick Dot” notation which means that my old obj.should_not_match other becomes obj.should.not.match other. Old Test::Unit tests need not be changed but if one wants to convert those, that change is a bit more profound and beyond the scope of this drivel—you can shamelessly raid the RSpec website or simply ask Unca Google (the test/ directory in the Test::Spec distribution also has self-tests to refer to).
Test::Spec, like Test::Unit, does not come with a mocking framework so you must select one of the existing ones—I am going with FlexMock. Mocha is apparently also good but I had a bad experience trying to mock/stub methods (i.e. it did not work so I gave up). It does seem that using FlexMock with Test::Spec means having to explicitly call #mock_verify on the mock objects which may have something to do with how Test::Unit normally handles its scopes (or may not, who knows).
For rs, the changes were fairly straightforward and I am doing the transition in two steps: for the first merge, I created $rs/test/vendor/ and stuck both FlexMock and Test::Spec in there to avoid depending (and having co-developers depend) on RubyGems and having to download additional software. I also revised the Rakefile slightly:1 2 3 4 |
# This goes in the TestTask t.libs = [LIB, TEST, TEST_VENDOR] t.options = '-rs' # Spec-style output t.ruby_opts = ['-r test/spec' ] # Automatically loaded |
/Edit: gave up on Mocha/