pending("insert reason here") 2

Posted by David Sat, 23 Jun 2007 17:04:00 GMT

In RSpec-1.0, we introduced a Not Yet Implemented feature. When you say …

it "should do something"

... with no block, the summary report lists that example as not implemented.

37 examples, 0 failures, 1 not implemented

As I started to use this I found myself doing stuff like this:

it "should do something" 
# do
#   here.is(the).actual(implementation).but(commented).out
# end

This made me sad. I hate having things that are commented out like that, even if the summary report draws my attention to it.

Then came a conversation with Dan about rbehave. In his article introducing rbehave, Dan talks about identifying pending scenarios so instead of getting failures while he’s working on the objects that must implement the behaviour, he gets a nice list of scenarios that should pass pending the completion of those objects. We discussed the similarities and differences between the Not Yet Implemented feature in RSpec and the Pending feature in rbehave and agreed that RSpec should have the pending method.

And so it has come to pass.

RSpec (trunk, as of rev 2118 – will be included in 1.0.6) still supports calling #it with no block, but now also supports the #pending method, allowing you to say:

describe "pending example (using pending method)" do
  it %Q|should be reported as "PENDING: for some reason"| do
    pending("for some reason")
  end
end

describe "pending example (with no block)" do
  it %Q|should be reported as "PENDING: Not Yet Implemented"|
end

And hear:

$ ruby bin/spec examples/pending_example.rb -fs

pending example (using pending method)
- should be reported as "PENDING: for some reason" (PENDING: for some reason)

pending example (with no block)
- should be reported as "PENDING: Not Yet Implemented" (PENDING: Not Yet Implemented)

Finished in 0.006639 seconds

2 examples, 0 failures, 2 pending

The #pending method raises a Spec::DSL::ExamplePendingError, which gets reported, in this case, as “PENDING: for some reason”. If you leave off the block the example will be reported as “PENDING: Not Yet Implemented”. Either way, the summary will combine these two types of pending examples as just “pending”.

Describe it with RSpec 2

Posted by David Sun, 11 Mar 2007 05:10:00 GMT

module BddTools
  describe RSpec do
    it "should help you get the words right" do
      Kernel.should respond_to(:describe)
      Behaviour.should respond_to(:it)
    end
  end
end

That code produces this output:

BddTools::RSpec
- should help you get the words right

Behaviour Driven Development is all about getting the words right.

Dan North has just registered rbehave at rubyforge and is using rspec to drive ITS behaviour. Getting started, he felt that “context” and “specify” weren’t speaking to him, so he wrapped them in “describe” and “it” to create the syntax in the example above.

These new words have been added to rspec’s trunk and will be released with rspec-0.8.3. Combined with their elder siblings “context” and “specify”, you’ll now be able to choose from a wider set of words to get your specs to “speak”.

Keep your eyes peeled for rbehave, an Acceptance Testing Framework that provides a Story Runner designed to promote communication between Customers, Developers and Testers. Combine rbehave’s Story Runner with rspec describing lower level behaviours and you’ll have the beginnings of the perfect toolset for a BDD project in Ruby.