Categories
Ruby

Unimplemented specs in RSpec

One of RSpec‘s many neat features is the ability to insert placeholder specs. These allow you to list a whole bunch of expected behaviour up front, without having to implement either the specs or the code, and without creating a huge swath of failing specs. All you need to do is omit the body of the specify or it block. Here’s a trivial example:

describe "The string 'foo'" do
  before do
    @foo = 'foo'
  end
  
  it "should be three characters long" do
    @foo.size.should == 3
  end
  
  it "should be capitalised to 'Foo'"
end
$ spec -f s foo_spec.rb                     

The string 'foo'
- should be three characters long
- should be capitalised to 'Foo' (NOT IMPLEMENTED)

Finished in 0.011201 seconds

2 examples, 0 failures, 1 not implemented

[tags]ruby,rspec[/tags]

2 replies on “Unimplemented specs in RSpec”

looks like you can also do

it “should do something” do
pending “an announcement”
end

or

it “should do something” do
pending “an announcement” do
end
end

Leave a Reply