RSpec on Rails

Hey everyone,

I was pleased to notice that RSpec has caught the attention of some
other Railers. It’s great to see something that I’ve so much effort
into start getting attention from folks that I respect.

I figured I ought to chime in here and let you know the current state
of RSpec, and the future, including integration with Rails.

RSpec development was initially done in Monotone[1] and I put up a
little place holder on http://rspec.rubyforge.org/. This saw a couple
downloads, and use from myself and the other two developers (Dave
Astels and Aslak Hellesoy). I knew all along that what we were doing
was cool, and I felt very strongly that everyone should be using it.
I had absolutely no idea that anyone would actually care. I have been
pleasantly surprised, to say the least.

So, RSpec development has been suffering some growing pains. The
current need is to get the revision history moved out from Monotone to
something a little more mainstream. This is not Monotone’s fault,
it’s the world’s fault for not using Monotone. I’ve pretty much
settled on Subversion, but I’ve been procrastinating setting up a new
repository because RubyForge is supposed to get Subversion support
“soon” and I don’t want to have to go updating URLs repeatedly. Once
the revision history is moved to Subversion[2], I can continue on new
developments. I’ve been waiting (im)patiently for Subversion on
RubyForge, but I don’t think I’m going to wait much longer. Noting
personal against RubyForge, I was just hoping it’d be there by now.

Planned new developments are numerous. After Jim W.'s excellent
talk on DSLs, some of the ThoughtWorkers and I discussed turning RSpec
into a “Behaviour Description Language”. I think Obie can be credited
with this. The rumours are true, there will be a DSL for RSpec. That
doesn’t mean, though, that you should let that keep you from using
RSpec. The existing (Test::Unit-like) interface will continue to be
supported for the forseeable future. You’ll have a choice of using
the DSL, or the Spec::Context interace.

Other developments:

  • GUI runners: one in RubyCocoa for OS X (some day soon, I promise),
    and I’ll probably end up doing one in GTK+ just to keep the Linux kids
    happy.
  • Eclipse integration with RDT.
  • A textmate plugin would be nice, but I won’t be working on this.

There has been talk about integrating RSpec with Rails to replace
existing Test::Unit integration, and I think this is a wonderful idea.
It’s also being worked on. I have a launch to deal with in Real Life
this week, but as soon as things die down a bit, I’m going to be
writing an RSpec plugin for Rails. This basically entails writing a
Spec task for rake, and re-writing the functional testing stuff to be
RSpec.

Some examples of what you’ll see. Instead of:

def test_should_redirect_to_list_after_creation
post :create, {:name => ‘foobar’}

assert_redirected_to :action => :list

end

You might see:

def redirect_to_list_after_creation
{post :create, {:name => ‘foobar’}}.should_redirect_to :action =>
:list
end

Or, as a DSL (proposed layout):

specification “Redirect to list after creation.” do
{post :create, {:name => ‘foobar’}}.should_redirect_to :action =>
:list
end

(The DSL is actually way more impressive because it doesn’t require
the module/class overhead that the Test::Unit and Spec::Context
interfaces do. So the DSL is a complete specification, while the
first two examples are fragments.)

So, this is in the works.

This should go without saying, but I’m going to point out anyways: I
am not interested in hearing or seeing any of the following: 1)
discussion about whether or not RSpec is useful, or provides an
improvement over TDD/Test::Unit or your mom’s favourite unit
verification tool, 2) critique of either of the proposed formats for
testing, since neither has been implemented and will be subject to my
change according to my whim, 3) personal insults[3].

That said, I am interested in comments, suggestions, reasonable
patches, and sexual favours.

Hope this clears up the muddy RSpec waters.

-Steven

  1. Monotone is the ass-kickinest SCM. Hasn’t dominated the world yet,
    though.
  2. This is proving more difficult than expected. If you have
    experience with Tailor moving monotone history to Subversion, please
    email me off list. I just can’t get Tailor to play well.
  3. I’ve only received one to date. My mom told me he’s just jealous.