Kerry Buckley What’s the simplest thing that could possibly go wrong?

29 July 2007

Unimplemented specs in RSpec

Filed under: Ruby — Kerry Buckley @ 10:36 am

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 Comments »

  1. How To Update Facebook, Twitter, and Kopete’s Status All At Once…

    Trackback by Ben Kudria — 16 August 2007 @ 8:01 pm

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

    Comment by roger — 15 December 2009 @ 5:06 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment

You must be logged in to post a comment.

Powered by WordPress