[rspec-devel] [ANN] quicktest - an RSpec wrapper for in-lining tests

greg weber webs.dev at gmail.com
Tue Feb 26 07:56:08 EST 2008

Quicktest is a utility for inlining ruby unit tests with the ruby code under

The typical test driven development workflow requires constant switching
between the file containg the source code and the the file containg the
tests. When creating code, it can be more convenient to place tests
immediately after the code you are writing.  After the code has been
written, it may be a good idea to move it to another file, but the option to
permanently keep tests with the source is available (useful for scripts).

Quicktest is designed to support quick tests in a framework agnostic way.
Currently, only an rspec testrunner is available, but it is trivial to write
one for another testing framework.

Quicktest uses method tracing to know the method you are testing. By default
the output of a failed test will show the object and method name.

To test a method, place another method called 'quicktest' immediately after
the quicktest method has three OPTIONAL arguments
- the test runner object
- a reference to self
- a method object for the method under test

run with spec -r quicktest file_to_test

There is a convenience script so that you can just run

   quickspec file_to_test

- leaving test code in with your production code is not necessarily a good
idea, but there is almost no runtime overhead to doing so since ruby will
not evaluate code in a method until the method is invoked
- quicktest instance methods not working properly? if the class (or one of
its ancestors) is overriding method tracing than including QuickTest::Tracer
will fix it.

example: run with bin/quickspec

class Foo
  attr_reader :bar

  def initialize
    @bar = true
  def quicktest t, s
    t.it "bar should be initialized to true" do
      s.bar.should == true

  def self.hello arg
    "hello" + arg
  def self.quicktest t, s, meth
    t.it "should prepend 'hello' to its argument" do
      meth["world"].should == 'hello world' # error - no space 'helloworld'

Running quicktest on the above outputs the following:

'Foo hello should prepend 'hello' to its argument' FAILED
expected: "hello world",
     got: "helloworld" (using ==)
./README:22:in `quicktest'
/home/greg/quicktest/lib/quicktest.rb:65:in `instance_eval'
/home/greg/quicktest/lib/quicktest.rb:65:in `run_tests'

Finished in 0.008338 seconds

2 examples, 1 failure
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-devel/attachments/20080226/a36a553c/attachment.html 

More information about the rspec-devel mailing list