[rspec-users] Why RSpec?

Matt Wynne matt at mattwynne.net
Wed Apr 22 20:02:47 EDT 2009

On 22 Apr 2009, at 17:52, Andrew Vit wrote:

> On Apr 22, 2009, at 4:25 AM, Amos King wrote:
>> I wasn't thinking about a gun.  I was just wondering if there is some
>> underlying reason that I'm missing.  Is there a background structure
>> that I'm not grasping?  Is there a huge piece of functionality that
>> I'm missing?  Is it faster than Test:Unit or Shoulda?
>> Amos(adkron)
> Personally, I can't think of one single huge piece of functionality  
> that makes RSpec win over TestUnit, but it's a whole bunch of little  
> things.
> It can be faster if you make use of mocks/stubs, and separation  
> between layers: you can test your controllers without having to  
> render the views.
> Shoulda is good too. It adds some of the features that RSpec  
> brought, like contexts, but having used Shoulda for over a year and  
> recently using RSpec on a new project, I can say that I prefer RSpec  
> overall... keep in mind Shoulda's macros and matchers are available  
> in RSpec too.
> describe RSpec, "versus TestUnit" do
>  it { should read_fluently }
> end
> Yes, a lot of the most visible differences seem to be around the  
> syntax, but the point is that it helps you think more fluidly about  
> what you're actually trying to do. TestUnit adds mental baggage for  
> up-front testing and the tests have a backward-looking feel, in  
> other words, they read more like they're verifying what should have  
> happened after it's done. RSpec tests read more expressively as  
> looking forward to what you would like to achieve, what "should"  
> happen.
> While the tests are still pure ruby, they read almost like pure  
> English, especially if you take a little extra effort to encapsulate  
> some of the hairy logic into your own custom matchers. The specs can  
> convey their intent much more clearly, instead of only serving as  
> verification of your app's performance. Your spec suite becomes very  
> readable (to a developer at least) as behaviour documentation,  
> without needing to slow down to work it out too much. That's not to  
> say you can't write readable tests in Shoulda or TestUnit, but RSpec  
> helps you frame them better and convey what you mean more clearly.
> Cheers,
> Andrew Vit

+1 Andrew.

Thanks for summing up the subtle benefits so well.

Also, I would add - RSpec has a solid community of extremely helpful,  
thoughtful and patient people who will guide you though as you learn  
BDD / TDD. I think that's a great reflection of the software itself.

Matt Wynne

More information about the rspec-users mailing list