RSpec 1.1 17

Posted by David Fri, 14 Dec 2007 06:54:00 GMT

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.

Comments

Leave a response

  1. Avatar
    Ben Mabey Fri, 14 Dec 2007 06:58:18 GMT

    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. Avatar
    Mikong Fri, 14 Dec 2007 08:11:50 GMT

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

  3. Avatar
    beenhero Fri, 14 Dec 2007 15:05:42 GMT

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

  4. Avatar
    Robby Russell Fri, 14 Dec 2007 16:41:46 GMT

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

  5. Avatar
    Nathan Youngman Fri, 14 Dec 2007 17:47:06 GMT

    Awesome… upgrading right away.

    Support for Rails 2.01… I think you mean “ruby script/plugin install”.

  6. Avatar
    David Chelimsky Fri, 14 Dec 2007 19:16:31 GMT

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

  7. Avatar
    Priit Tamboom Sun, 16 Dec 2007 09:08:07 GMT

    Thanks for really great work!

  8. Avatar
    Andrew Vit Mon, 17 Dec 2007 01:35:54 GMT

    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?

    I’m not a RSpec user (yet), so forgive me if this seems like an odd question… It just seemed to me that spec vs test were two separate worlds so I’m wondering where things will converge for a new interoperable “standard”.

  9. Avatar
    http://blog.divoxx.com Mon, 17 Dec 2007 03:16:55 GMT

    Neat! :)

  10. Avatar
    Pius Mon, 17 Dec 2007 15:31:27 GMT

    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. Avatar
    David Chelimsky Mon, 17 Dec 2007 18:36:43 GMT

    @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. Avatar
    Pius Mon, 17 Dec 2007 19:21:32 GMT

    Nice, thanks for the prompt response!

  13. Avatar
    robinhoode Tue, 18 Dec 2007 13:02:04 GMT

    Ooo baby, Ooo baby, Ooo baby..

    /me starts up his command prompt in extreme anticipation

  14. Avatar
    Justin Blake Tue, 18 Dec 2007 23:00:46 GMT

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

  15. Avatar
    Lina T. Fri, 21 Dec 2007 00:32:22 GMT

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

  16. Avatar
    Anny Mon, 31 Dec 2007 14:10:56 GMT

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

  17. Avatar
    Helder Thu, 03 Jan 2008 21:24:12 GMT

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

Comments