RSpec 1.1

December 14th, 2007

The RSpec Development Team is pleased as glug (that’s kind of like punch, but more festive) to announce RSpec-1.1.0.

Thanks to all who have contributed patches over the last few months. Big thanks to Dan North and Brian Takita for their important work on this release. Dan contributed his rbehave framework which is now the Story Runner. Brian patiently did a TON of refactoring around interoperability with Test::Unit, and the result is a much cleaner RSpec core, and a clean adapter model that gets loaded when Test::Unit is on the path.

RSpec 1.1 brings four significant changes for RSpec users:

  • The RSpec Story Runner
  • Nested Example Groups
  • Support for Rails 2.0.1
  • Test::Unit interoperability

Story Runner

The RSpec Story Runner is Dan North’s rbehave framework merged into RSpec. The Story Runner is a framework for expressing high level requirements in the form of executable User Stories with Scenarios that represent Customer Acceptance Tests.

RSpec 1.1 also ships with a Ruby on Rails extension called RailsStory, which lets you write executable user stories for your rails apps as well.

Nested Example Groups

Now you can nest groups to organize things a bit better:


describe RubyDeveloper do

before(:each) do @ruby_developer = RubyDeveloper.new end

describe "using RSpec 1.1.0" do

before(:each) do
  @ruby_developer.use_rspec('1.1.0')
end

it "should be able to nest example groups" do
  @ruby_developer.should be_able_to_nest_example_groups
end

end

describe “using RSpec 1.0.1″ do

before(:each) do
  @ruby_developer.use_rspec('1.0.8')
end

it "should not be able to nest example groups" do
  @ruby_developer.should_not be_able_to_nest_example_groups
end

end

end

Running this outputs:

RubyDeveloper using RSpec 1.1.0
- should be able to nest example groups

RubyDeveloper using RSpec 1.0.8 - should not be able to nest example groups

== Support for Rails 2.0.1

gem install rails
rails myapp
ruby script/plugin install http://rspec.rubyforge.org/svn/tags/REL_1_1_0/rspec
ruby script/plugin install http://rspec.rubyforge.org/svn/tags/REL_1_1_0/rspec_on_rails
script/generate rspec

Test::Unit Interoperability

Contrary to popular belief, Spec::Rails, RSpec’s Ruby on Rails plugin, has been a Test::Unit wrapper since the the 0.7 release in November of 2006. RSpec 1.1 ups the ante though, offering a smooth transition from Test::Unit to RSpec with or without Rails:

1. Start with a TestCase:


require 'test/unit'

class TransitionTest < Test::Unit::TestCase def test_should_be_smooth transition = Transition.new( :from => "Test::Unit::TestCase", :to => "Spec::ExampleGroup" ) assert_equal "really smooth", transition.in_practice end end

2. Require ‘spec’


require 'test/unit'
require 'spec'

class TransitionTest < Test::Unit::TestCase def test_should_be_smooth transition = Transition.new( :from => "Test::Unit::TestCase", :to => "Spec::ExampleGroup" ) assert_equal "really smooth", transition.in_practice end end

3. Convert TestCase to ExampleGroup


require 'test/unit'
require 'spec'

describe "transitioning from TestCase to ExampleGroup" do def test_should_be_smooth transition = Transition.new( :from => "Test::Unit::TestCase", :to => "Spec::ExampleGroup" ) assert_equal "really smooth", transition.in_practice end end

4. Convert test methods to examples


require 'test/unit'
require 'spec'

describe "transitioning from TestCase to ExampleGroup" do it "should be smooth" do transition = Transition.new( :from => "Test::Unit::TestCase", :to => "Spec::ExampleGroup" ) assert_equal "really smooth", transition.in_practice end end

5. Convert assertions to expectations


require 'test/unit'
require 'spec'

describe "transitioning from TestCase to ExampleGroup" do it "should be smooth" do transition = Transition.new( :from => "Test::Unit::TestCase", :to => "Spec::ExampleGroup") transition.in_practice.should == "really smooth" end end

6. Un-require test/unit


require 'spec'

describe "transitioning from TestCase to ExampleGroup" do it "should be smooth" do transition = Transition.new( :from => "Test::Unit::TestCase", :to => "Spec::ExampleGroup" ) transition.in_practice.should == "really smooth" end end

At every one of these steps after step 2, you can run the file with the ruby command and you’ll be getting RSpec’s developer friendly output. This means that you can transition things as gradually as you like: no wholesale changes.

That’s the story. Thanks again to all who contributed and to all who continue do so.

17 Responses to “RSpec 1.1”

  1. Ben Mabey Says:

    Congrats! Thanks for all your hard work. I can’t wait to get the newly minted gem… The ride on trunk has been fun though. :)

  2. Mikong Says:

    Congrats! I’d like to try that nested examples feature. Just ran svn up in my project. :)

  3. beenhero Says:

    now, we get the RSpec1.1 and Rails 2.0.1, Cheers!

  4. Robby Russell Says:

    Sweet. I haven’t had a chance to play with the story runner yet. New project starting… so maybe it’s time. :-)

  5. Nathan Youngman Says:

    Awesome… upgrading right away.

    <p>Support for Rails 2.01&#8230; I think you mean &#8220;ruby script/plugin install&#8221;.</p>
    
  6. David Chelimsky Says:

    @Nathan – yes that’s what I meant. I updated the post. Thanks.

  7. Priit Tamboom Says:

    Thanks for really great work!

  8. Andrew Vit Says:

    So, if it’s interoperable with Test Unit, what does that mean for standardizing the location of test files? Is the transitioning “best/recommended” practice to eventually move your tests into the specs directory, or would it make sense to just keep stuff where it is?

    <p>I&#8217;m not a RSpec user (yet), so forgive me if this seems like an odd question&#8230; It just seemed to me that spec vs test were two separate worlds so I&#8217;m wondering where things will converge for a new interoperable &#8220;standard&#8221;.</p>
    
  9. http://blog.divoxx.com Says:

    Neat! :)

  10. Pius Says:

    Looks sweet! Unfortunately, upgrading from the release candidate breaks my tests. :( For whatever reason it can’t seem to load the fixtures properly and I get “can’t convert nil into String.”

  11. David Chelimsky Says:

    @Pius – that’s a regression that got introduced right before we released. We’ve fixed it in trunk and we’ll do a 1.1.1 release tonight.

  12. Pius Says:

    Nice, thanks for the prompt response!

  13. robinhoode Says:

    Ooo baby, Ooo baby, Ooo baby..

    <p>/me starts up his command prompt in extreme anticipation</p>
    
  14. Justin Blake Says:

    Nest example groups look sweet! This is really going to clean things up for me.

  15. Lina T. Says:

    Man you don’t even know how long I’ve waited for this since disabling my own Movable Type widget

  16. Anny Says:

    Happy holidays to you too. and a belated Christmas wishes..

  17. Helder Says:

    Wow, I loved the “really smooth” transition! Great work! I just feel a lot better about starting to learn it now :)