Rspec 2.0 in the works
January 25th, 2010
We’ve started to do some preliminary work on rspec-2.0, which we plan to release before Rails-3 goes final. At that point, the rspec-rails-2.0 plugin/gem will only work with rspec >= 2.0 and rails >= 3.0.
We’re committed to making the upgrade from rspec-1.x to rspec-2.0 as seamless as possible for most users, but extenders are going to see some differences. This is why we’re going to take our time with alpha, beta, and candidate releases.
Here are some of the improvements you can expect:
Modularity
Following the Rails and Merb models, Rspec-2 will be broken up into component gems and a meta-gem that depends on them. Most users will still gem install rspec, and doing so will install the component gems.
We’ve broken rspec up into 4 repos in the rspec account on github:
- rspec => meta gem that depends on the others
- rspec-core => runner and output formatters
- rspec-expectations =>
shouldand matchers - rspec-mocks => mocks and stubs
With separate component repos, you’ll be able to use rspec as you do today or mix and match components with other frameworks. This will also make it easier for contributors to contribute to the components they are interested in without worrying about other components.
New runner extracted from Micronaut
The rspec-core repository is a complete rewrite of the runner, which has been a big sore spot over the years for contributors and extenders. We extracted the runner from Micronaut, which is an Rspec-compatible framework written by Chad Humphries.
Micronaut has a simple and powerful metadata model, which allows us to easily slice and dice a spec suite in much the same way we do now with Cucumber using tags. It also helps to simplify rspec’s own specs (because you can access it from within an example).
Because we’re able to intercept examples before they are run, we’ll also be able to offer a clean extension API, allowing you to add structures like Merb’s given blocks without monkey patching. Less monkey patching == more maintainable.
Where we are today
While Micronaut runs the same specs that Rspec does, there are some different names for things, and there are some differences in the CLI as well. We’ve started to resolve some of the differences in rspec-core, but we have a way to go.
If you want to try it out and see what works and what doesn’t, you can either install the prerelease gems (2.0.0.a2 as of this writing):
[sudo] gem install rspec --prerelease
You can also grab the dev environment and have a look at the code. See the rspec-dev README for info.
Please do not start reporting issues yet as this will only slow us down.
There is a lot that works, but there is also a lot that doesn’t. Once we get to beta, we’ll be looking for feedback and contributions, but for now we just want to let you know where things are.
Rspec 2 uses Rspec as the root namespace and installs an rspec command instead of a spec command. Until we release 2.0.0 final, this will make it easy for you to keep things separate on your system and in your apps. Once we go final we’ll either alias the old names or release a separate backwards-compatibility wrapper gem that does this for you.
What’s next
We want to focus most of our efforts on rspec-2 at this point, so we don’t plan any new development on the rspec-1.x series. We’ll do bug-fix releases of rspec[-rails]-1.3, but no new features.
I’ll follow up with more information as it becomes clear. Look here for announcements about alpha and beta releases if you’re interested in trying it out early or getting involved.


January 25th, 2010 at 4:12 am
Great, will definitely try out the prerelease on a Rails 3 app I have.
Will The RSpec Book be updated to cover 2.0 before release, or is it shipping as is?
January 25th, 2010 at 8:40 am
I’m really looking forward to using v2.0 on my projects. Hopefully it will work for Sinatra apps as well!
January 25th, 2010 at 10:54 am
Is a prerelease gem for rspec-rails 2.0 also availible?
January 25th, 2010 at 10:55 am
By the way I get this error when trying to gem install the prerelease:
$ sudo gem install rspec –prerelease ERROR: Error installing rspec: rspec-core requires rspec-expectations (>= 2.0.0.a2, runtime)
January 25th, 2010 at 1:52 pm
David B - sounds like you have an older version of rubygems. Are you using 1.3.5?
January 26th, 2010 at 9:41 am
Fore sure.
$ gem -v
1.3.5
January 26th, 2010 at 9:42 am
Using Snow Leopards built in ruby 1.8.7 and rubygems (with sudo gem update –system to get me to 1.3.5)
January 26th, 2010 at 1:24 pm
@David - I’m using the same setup and I can remove all the rspec gems from my system, “sudo gem install rspec –prerelease” and all is well: http://gist.github.com/286830
I wonder what’s different about our systems?
January 27th, 2010 at 5:01 pm
Tried uninstalling rspec and rspec-rails before installing the prerelease but got the same error message anyway.
Not really sure where to go from here. I could survive just waiting for the final release.
However if you’d like me to run some specific tests to figure this issue out you could contact me as “dbackeus” on github.
February 2nd, 2010 at 6:19 pm
Like Luigi, I’m also wondering if you have plans to get this into The RSpec Book before it’s out in final form.
I just purchased the beta book and hope the updates can include something about 2.0’s changes so that I don’t have to piece it all together from blogs eventually. I won’t switch to Rails 3 right away, but it would still be great to have an appendix or a new chapter or two there when I need them.
February 3rd, 2010 at 7:13 am
Luigi and Steve - The RSpec Book will likely not include Rspec 2, but 99% of the info in the book will remain relevant. Most of the changes in Rspec-2 are under the hood and will only impact extenders.
February 4th, 2010 at 2:10 pm
David, thanks for the reassurance.
On a side note, I really appreciate all the thought and planning that has gone into the RSpec Book. I’m learning Ruby as my first real programming language (in my late 20s, no less), and it’s been slow-going with Rails because I haven’t felt confident about the process of writing apps or testing them. So your book is helping me start to intuit that process better, with the notion that you can write code from the perspective of the object calling a method, not the object that takes it (if I understand that right).
If I can suggest anything for the future, I think a book called something like “BDD Rails Recipes” (an updated Rails Recipes-type book where every solution is accomplished using the BDD process) would be just about the most helpful thing I could imagine. But regardless, thanks for all the work that’s gone into the current book.
February 18th, 2010 at 5:18 am
I just saw the RSpec book was postponed until April 30th. Does that mean it will be updated for RSpec 2.0? An extra two months should be enough to revise it, I guess. A confirmation would be great!
February 24th, 2010 at 3:41 am
Hey,
I just installed the prerelease gem no problem but it screwed up my ability to work with rspec 1.3.0. Is rspec 2.0 supposed to be able to run side by side with rspec 1.3. Did I miss something on my install?
Aside from that. RSpec is one of my favorite tools. Thank you for all your hard work getting it ready for Rails 3.
Jordan
February 26th, 2010 at 4:10 am
@Jordan - rubygem executables take a little known argument that you can use to specify the correct version:
spec _1.3.0_ spec
HTH
March 4th, 2010 at 2:46 pm
Is there currently any way of running rspec 2.0 with Spork?
March 5th, 2010 at 3:32 am
Not yet, Bern - rspec-2 doesn’t have drb support yet, but it will before long.
March 6th, 2010 at 1:44 am
Thanks David for your hard work.