[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Introducing SpecUnit

Trotter Cashion

10/12/2006 3:01:00 PM

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:trotter@eastmedia.com)
Copyright:: Copyright (c) 2006 Trotter Cashion
License:: Distributed under the MIT License

2 Answers

Bil Kleb

10/12/2006 5:01:00 PM

0

Trotter Cashion wrote:
> Hello everyone,

Hello.

> Two weeks ago at BarCamp NYC, I put together a little addition to
> Test::Unit that I'm tentatively calling SpecUnit.

While you were camping, Christian announced test/spec,

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-t...

It's nice to see all the activity in the BDD camp ground
these days.

Regards,
--
Bil Kleb
http://funit.rub...

Trotter Cashion

10/12/2006 8:38:00 PM

0

Bil,

test/spec looks pretty cool. However, I'm trying to take a more
lightweight approach with SpecUnit. If you look under the hood,
you'll notice that I'm not touching Test::Unit and am letting it run
like normal. Less coupling = fun.

- Trotter

On Oct 12, 2006, at 1:05 PM, Bil Kleb wrote:

> Trotter Cashion wrote:
>> Hello everyone,
>
> Hello.
>
>> Two weeks ago at BarCamp NYC, I put together a little addition
>> to Test::Unit that I'm tentatively calling SpecUnit.
>
> While you were camping, Christian announced test/spec,
>
> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-t...
>
> It's nice to see all the activity in the BDD camp ground
> these days.
>
> Regards,
> --
> Bil Kleb
> http://funit.rub...
>
>