= test/spec, a BDD interface for Test::Unit

Copyright (C) 2006 Christian Neukirchen <mailto:[email protected]>


== 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 been tested successfully with FlexMock and
Mocha.

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.)

test/spec adds two global methods, Object#should and Kernel.context.

You can use <tt>assert_*</tt> freely in specify-blocks; Object#should
works in plain Test::Unit test cases, too, but they will not be counted.


== Wrapped assertions

+assert_equal+:: <tt>should.equal</tt>, <tt>should ==</tt>
+assert_not_equal+:: <tt>should.not.equal</tt>, <tt>should.not ==</tt>
+assert_same+:: <tt>should.be</tt>
+assert_not_same+:: <tt>should.not.be</tt>
+assert_nil+:: <tt>should.be.nil</tt>
+assert_not_nil+:: <tt>should.not.be.nil</tt>
+assert_in_delta+:: <tt>should.be.close</tt>
+assert_match+:: <tt>should.match</tt>, <tt>should =~</tt>
+assert_no_match+:: <tt>should.not.match</tt>, <tt>should.not =~</tt>

+assert_instance_of+:: <tt>should.be.an.instance_of</tt>
+assert_kind_of+:: <tt>should.be.a.kind_of</tt>
+assert_respond_to+:: <tt>should.respond_to</tt>
+assert_raise+:: <tt>should.raise</tt>
+assert_nothing_raised+:: <tt>should.not.raise</tt>
+assert_throws+:: <tt>should.throw</tt>
+assert_nothing_thrown+:: <tt>should.not.throw</tt>

+assert_block+:: <tt>should.satisfy</tt>

(+a+, +an+ and +be+ without arguments are optional and no-ops.)


== Additional assertions

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

* <tt>should.not.satisfy</tt>
* <tt>should.include</tt>
* <tt>a.should.</tt>_predicate_ (works like <tt>assert
a.</tt>_predicate_<tt>?</tt>)
* <tt>a.should.be </tt>_operator_ (where _operator_ is one of <tt>></tt>, <tt>>=</tt>, <tt><</tt>, <tt><=</tt> or <tt>===</tt>)
* <tt>should.output</tt> (require test/spec/should-output)

If you write an useful general-purpose assertion, I'd like to hear of
it and may add it to the test/spec distribution.


== 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 <tt>--runner=specdox</tt> (or <tt>-rs</tt>) looks
like RSpec's output:

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

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

== should.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


== specrb

Since version 0.2, test/spec features a standalone test runner called
specrb. specrb is like an extended version of testrb, Test::Unit's
test runner, but has additional options. It can be used for
plain Test::Unit suites, too.

$ specrb -a -s -n should.output

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

Finished in 0.162571 seconds.

3 specifications (6 requirements), 0 failures

Run <tt>specrb --help</tt> for the usage.


== History

* September 29th, 2006: First public release 0.1.

* October 18th, 2006: Second public release 0.2.
* Better, module-based implementation
* Official support for FlexMock and Mocha
* More robust Should#output
* Should#_operator_
* Nested contexts
* Standalone test/spec runner, specrb


== Contact

Please mail bugs, suggestions and patches to
<mailto:[email protected]>.

Darcs repository ("darcs send" is welcome for patches):
http://chneukirchen.org/repos/testspec


== Thanks to

* Eero Saynatkari for writing <tt>should.output</tt>.
* 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/chneukirchen>

test/spec is licensed under the same terms as Ruby itself.

Please mail bugs, feature requests or patches to the mail addresses
found above or use IRC[irc://freenode.net/#ruby-lang] to contact the
developer.


== Links

Behavior-Driven Development:: <http://behaviour-driven.org/>
RSpec:: <http://rspec.rubyforge.org/>
script.aculo.us testing:: <http://mir.aculo.us/articles/2006/08/29/bdd-style-javascript-testing>

FlexMock:: <http://onestepback.org/software/flexmock/>
Mocha:: <http://mocha.rubyforge.org/>

Christian Neukirchen:: <http://chneukirchen.org/>