Introducing SpecUnit

Hello everyone,
Two weeks ago at BarCamp NYC, I put together a little addition to
Test::Unit that I’m tentatively calling SpecUnit. It clocks in at 61
lines, is well tested, and adds nested contexts to Test::Unit.
Install with ‘sudo gem install spec-unit’. Give it a look and let me
know what you think. Below is the short readme I put together.

=Introduction
SpecUnit is an extension to Test::Unit that allows tests to be grouped
into contexts. The idea of contexts comes from rSpec, which is a BDD
framework for Ruby. rSpec is a great testing framework, but I built
SpecUnit out of the desire to make use of tools already in existence
for Test::Unit and to provide a lightweight means of making use of
contexts.

=Usage
To use SpecUnit, simply require ‘spec-unit’

require ‘test/unit’
require ‘spec-unit’

class TestBlob < Test::Unit::TestCase
include SpecUnit

 def setup
   @object = Blob.new
 end

 context 'when empty' do
   def specify_should_be_empty
     assert @object.empty?
   end
 end

 context 'when has one item' do
   def setup
     @object.add(2)
   end

   def specify_has_length_of_one
     assert_equal 1, @object.length
   end
 end

end

As you can see above, contexts can be nested. Setups are run outside
in, while teardowns are run inside out. There should be no namespace
conflicts as the library is fairly well tested, but let me know if you
find any.

=Caveats
I wrote this in a weekend, so there may be some things I didn’t think
to test in my tests. Also, there are probably a number of cool
features I could add. Let me know if there are any you want, and I’ll
consider adding them. Submitting patches makes it much more likely
that I’ll implement your feature.

=More Documentation
Read the tests, let me know if they’re terribly unreadable. I’ll add
some documentation to the SpecUnit module later. If you want to add
documentation, please do. Send me a patch, and I will include it.

=About
Author:: Trotter Cashion (mailto:[email protected])
Copyright:: Copyright © 2006 Trotter Cashion
License:: Distributed under the MIT License

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs