[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

[ANN] test/spec 0.1, a BDD interface for Test::Unit

Christian Neukirchen

9/29/2006 4:34:00 PM

Hello,

today I'm releasing test/spec, a library to do BDD with Test::Unit.

== What is test/spec?

test/spec layers an RSpec-inspired interface on top of Test::Unit, so
you can mix TDD and BDD (Behavior-Driven Development).

test/spec is a clean-room implementation that maps most kinds of
Test::Unit assertions to a `should'-like syntax.

Consider this Test::Unit test case:

class TestFoo < Test::Unit::TestCase
def test_should_bar
assert_equal 5, 2 + 3
end
end

In test/spec, it looks like this:

require 'test/spec'

context "Foo" do
specify "should bar" do
(2 + 3).should.equal 5
end
end

test/spec does not include a mocking/stubbing-framework; use whichever
you like to.

test/spec has no dependencies outside Ruby 1.8.

== Mixing test/spec and test/unit

test/spec and Test::Unit contexts/test cases can be intermixed freely,
run in the same test and live in the same files. You can just add them
to your Rake::TestTask, too. test/spec allows you to leverage your
full existing Test::Unit infrastructure.

test/spec does not change Test::Unit with the exception of
monkey-patching Test::Unit::TestSuite to order the test cases before
running them. (This should not do any harm, but if you know a way
around it, please tell me.)

You can use assert_* freely in specify-blocks; Object#should works in
Test::Unit test cases, too, but doesn't increase the assertion count.

== Wrapped assertions

assert_equal: should.equal, should ==
assert_not_equal: should.not.equal, should.not ==
assert_same: should.be
assert_not_same: should.not.be
assert_nil: should.be.nil
assert_not_nil: should.not.be.nil

assert_in_delta: should.be.close
assert_match: should.match, should =~
assert_no_match: should.not.match, should.not =~

assert_instance_of: should.be.an.instance_of
assert_kind_of: should.be.a.kind_of
assert_respond_to: should.respond_to

assert_raise: should.raise
assert_nothing_raised: should.not.raise
assert_throws: should.throw
assert_nothing_thrown: should.not.throw
assert_block: should.satisfy

== Additional assertions

These assertions are not included in Test::Unit, but have been added
to test/spec for convenience:

* should.not.satisfy
* a.should.<predicate> (works like assert a.<predicate>?)
* should.output, to check what is printed

== SpecDox and RDox

test/spec adds two additional test runners to Test::Unit, based on the
console runner but with a different output format.

SpecDox, run with --runner=specdox (or -rs) looks
like RSpec's output:

spec.output
- works for print
- works for puts
- works with readline

RDox, run with --runner=rdox (or -rr) can be
included for RDoc documentation (e.g. see SPECS):

== spec.output
* works for print
* works for puts
* works with readline

SpecDox and RDox work for Test::Unit too:

$ ruby -r test/spec test/testunit/test_testresult.rb -rs

Test::Unit::TC_TestResult
- fault notification
- passed?
- result changed notification

Finished in 0.106647 seconds.

3 specifications (30 requirements), 0 failures

== Thanks to

* Eero Saynatkari for writing should.output.
* Thomas Fuchs for script.aculo.us BDD testing which convinced me.
* Dave Astels for BDD.
* The RSpec team for API inspiration.
* Nathaniel Talbott for Test::Unit.

== Copying

Copyright (C) 2006 Christian Neukirchen <http://purl.org/net/chneuk...
test/spec is licensed under the same terms as Ruby itself.

== Where can I get it?

You can download test/spec 0.1 at

http://chneuk.../releases/testspec-0....

Alternatively, you can checkout from the development repository with:

darcs get http://chneuk.../repo...

(Patches using "darcs send" are most welcome.)

== Links

Behavior-Driven Development:: <http://behaviour-drive...
RSpec:: <http://rspec.rubyforg...
script.aculo.us testing:: <http://mir.aculo.us/articles/2006/08/29/bdd-style-javascript-t...


Happy hacking and have a nice day,
Christian Neukirchen

9861cf92ec39cce7a5e96504f1fdb6f0 testspec-0.1.0.tar.gz
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneuk...

8 Answers

Bil Kleb

10/3/2006 1:13:00 PM

0

Christian Neukirchen wrote:
> Hello,

Hi.

> today I'm releasing test/spec, a library to do BDD with Test::Unit.

This is most excellent news.

Is Rspec still alive? (This seems to replace it, and fair exceed it.)

Regards,
--
Bil Kleb
http://fun3d.lar...

Rob Sanheim

10/3/2006 1:32:00 PM

0

On 9/29/06, Christian Neukirchen <chneukirchen@gmail.com> wrote:
> Hello,
[snip]
> You can use assert_* freely in specify-blocks; Object#should works in
> Test::Unit test cases, too, but doesn't increase the assertion count.
[/snip]
> Happy hacking and have a nice day,
> Christian Neukirchen
>
> 9861cf92ec39cce7a5e96504f1fdb6f0 testspec-0.1.0.tar.gz
> --
> Christian Neukirchen <chneukirchen@gmail.com> http://chneuk...


Looks very interesting.

Is there a reason that calls to "should" don't increase the assertion
count? Seeing as they are sort of equivalent, and seeing the
assertion count is a helpful thing, it would be nice. Or maybe there
should be a general "verification count" that includes calls to
should?

Here is one hack to do the assertion counts, btw:
http://www.io.com/~wazmo/blog/archives/2006_05.h...

- rob

--
http://www.robs...
http://www.seekin...
http://www.a...

Christian Neukirchen

10/3/2006 9:00:00 PM

0

Bil Kleb <Bil.Kleb@NASA.gov> writes:

> Christian Neukirchen wrote:
>> Hello,
>
> Hi.
>
>> today I'm releasing test/spec, a library to do BDD with Test::Unit.
>
> This is most excellent news.
>
> Is Rspec still alive?

AFAICS, Rspec is still alive, but I don't know how many people use it.
It certainly didn't get as popular as I thought.

> (This seems to replace it, and fair exceed it.)

It is not my intent to fight against RSpec, but to provide a suitable
alternative for people that want to use BDD and stick to Test::Unit.

> Regards,
> Bil Kleb
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneuk...

Christian Neukirchen

10/3/2006 9:03:00 PM

0

"Rob Sanheim" <rsanheim@gmail.com> writes:

> On 9/29/06, Christian Neukirchen <chneukirchen@gmail.com> wrote:
>> Hello,
> [snip]
>> You can use assert_* freely in specify-blocks; Object#should works in
>> Test::Unit test cases, too, but doesn't increase the assertion count.
> [/snip]
>> Happy hacking and have a nice day,
>> Christian Neukirchen
>>
>> 9861cf92ec39cce7a5e96504f1fdb6f0 testspec-0.1.0.tar.gz
>> --
>> Christian Neukirchen <chneukirchen@gmail.com> http://chneuk...
>
>
> Looks very interesting.
>
> Is there a reason that calls to "should" don't increase the assertion
> count? Seeing as they are sort of equivalent, and seeing the
> assertion count is a helpful thing, it would be nice. Or maybe there
> should be a general "verification count" that includes calls to
> should?
>
> Here is one hack to do the assertion counts, btw:
> http://www.io.com/~wazmo/blog/archives/2006_05.h...

This hack is done by the context/specify blocks, inside them, #shoulds
are counted. However, I didn't want to monkeypatch Test::Unit
directly, so #shoulds in "ordinary" Test::Unit test_* method won't be
counted.

Since you usually want to use context/specify blocks, this is not a
problem in practice.

> - rob
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneuk...

David Chelimsky

10/11/2006 9:02:00 PM

0

On 10/3/06, Bil Kleb <Bil.Kleb@nasa.gov> wrote:
> Christian Neukirchen wrote:
> > Hello,
>
> Hi.
>
> > today I'm releasing test/spec, a library to do BDD with Test::Unit.
>
> This is most excellent news.
>
> Is Rspec still alive? (This seems to replace it, and fair exceed it.)

RSpec is still very much alive:

http://rspec.rub...

I'm curious as to why you say this exceed's rspec? I'm not looking for
a battle here, there are enough people using rspec that if there's
some perception of missing goodness, I'd like to know what we can add
to it.

Thanks,
David

Bil Kleb

10/11/2006 9:27:00 PM

0

David Chelimsky wrote:
>
> I'm curious as to why you say this exceed's rspec? I'm not looking for
> a battle here, there are enough people using rspec that if there's
> some perception of missing goodness, I'd like to know what we can add
> to it.

I haven't looked a rspec in a while, but test/spec seemed
to give all that rspec offered, plus the ability to bridge
the two worlds if you so chose.

Regards,
--
Bil Kleb
http://fun3d.lar...

David Chelimsky

10/11/2006 9:49:00 PM

0

On 10/11/06, Bil Kleb <Bil.Kleb@nasa.gov> wrote:
> David Chelimsky wrote:
> >
> > I'm curious as to why you say this exceed's rspec? I'm not looking for
> > a battle here, there are enough people using rspec that if there's
> > some perception of missing goodness, I'd like to know what we can add
> > to it.
>
> I haven't looked a rspec in a while, but test/spec seemed
> to give all that rspec offered, plus the ability to bridge
> the two worlds if you so chose.

Got it. Thanks for replying.

Cheers,
David

Christian Neukirchen

10/13/2006 5:26:00 PM

0

Bil Kleb <Bil.Kleb@NASA.gov> writes:

> David Chelimsky wrote:
>> I'm curious as to why you say this exceed's rspec? I'm not looking
>> for
>> a battle here, there are enough people using rspec that if there's
>> some perception of missing goodness, I'd like to know what we can add
>> to it.
>
> I haven't looked a rspec in a while, but test/spec seemed
> to give all that rspec offered, plus the ability to bridge
> the two worlds if you so chose.

One part that test/spec doesn't implement intentionally is mocking,
but in the darcs trunk, at least flexmock and mocha work nicely.

Also, RSpec has better Rails integration---I may port/write this some
day, but I'm not using Rails at the moment.

Patches and additions are welcome, of course.

> Bil Kleb
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneuk...