Topic: Why RSpec when you've got Cucumber?

I'm just getting in to doing some grown-up Rails development with BDD. I have my stories written for the first iteration and I have some EPICs as well. I've had my customer write some very general stories which he's done very well. Actually, I'm surprised I've not seen this explicitly covered as a story generation technique but we created some personas and he and I wrote a journey of each role working through a make believe session on the web app. We managed to avoid going into too much UI detail and just focused on what each persona needed to achieve. From this I could extract the short stories in the form "A role can..." on to Pivotal Tracker. The customer and I are  working through the stories on PT and creating the acceptance test in the form "Try ...". The "Try... " tests seem to fall neatly into Given/When/THen statements. So far, so good. We've got some relevant cucumber features written for the first iteration.

BUT!!.. the RSpec side of things just seems too detailed. Is it possible that all my testing can be done on the outer Cucumber ring?

In Mike Cohn's "User Stories Applied" book, on page 70 he describes a unit-test that might check to see if a credit card can have the dates February 30th and June 31st. But this is something I could test at the Cucumber level? If it passed Cucumber it passes the whole thing and I can see where the test is failing because I'd have a fail next to the "Try a credit card with an impossible date" scenario.

Perhaps this will all become clear as I get further into BDD but I'd appreciate people's thoughts on where acceptance tests end and unit tests begin.

Re: Why RSpec when you've got Cucumber?

Hello Kevin,

I use both Cucumber (same way you do) and rSpec. With Cucumber it might be too long and tedious to create stories for each posible use case and error paths in an application (and time consuming to run the Cucumber scenarios). So I use Cucumber for the most important and common use cases while with rSpec I try to test everything I can at the model level.

There is a long thread about this topic in the Cucumber mailing list with lot of interesting comments: http://groups.google.com/group/cukes/br … p;q=rspec#


HTH,
Florent

Re: Why RSpec when you've got Cucumber?

Thanks Florent,

That's a really interesting discussion.

The Sat Nav analogy  from Joseph Wilk was a good one. I'll repeat it here in case someone is interested:

Joseph Wilk wrote:

I used an analogy at Scotland on Rails that might be helpful. I was
thinking about Rspec and Cucumber in terms of planning a driving route
between London and Edinburgh.

Cucumber would test the output, the value:

"Then I am in Edinburgh"

So while driving, knowing I'm not in Edinburgh yet is not really not
that much help for me. Its my end value but the feedback loop is too
big. I could drive to Edinburgh via the USA and still achieve the
value. I like to think of Rspec as a route planner which is giving me
continuous feedback, helping me improve the design of my route. The
feedback loop is fast and it helps me get to my value.

You checkout the presentation:
http://blog.josephwilk.net/ruby/outside … cumber-...

It's interesting to see one person mention that for smaller projects an entirely cuke based project was feasible. I just can't see the point in writing a model validation that essentially checks if Rails is working properly. Perhaps if it's an interesting or novel validation then it's worth dropping down to RSpec.

Re: Why RSpec when you've got Cucumber?

Kevin Monk wrote:

I just can't see the point in writing a model validation that essentially checks if Rails is working properly. Perhaps if it's an interesting or novel validation then it's worth dropping down to RSpec.

Sure, a model spec should not check if Rails is working properly, only test your own model code.