Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TDD/BDD Rails Cucumber / RSpec duplication

Can someone please clarify using a SIMPLE user story the full slice of what Cucumber would be used for and what RSpec would be used for? I purchased the RSpec book the other day and have been going through it. The author seems to be quite vague at times.

What I'm thinking of if the user story is something like (please excuse the syntax incorrectness, this is just so you get the point):

When a user enters an invalid telephone number then they get a message saying "Invalid Telephone Number"

If I write out all the code for Cucumber to check for this and then write the rspec stuff, I'm basically duplicating my test. Is there a scenario to explain how the cucumber test should be different from the rspec test?

I feel like you would be duplicating tests on both levels all the time.

If there is no definitive answer on this, I'm going to begin to think the Cucumber people just didn't want to step on the RSpec people's toes.

Please help. I feel like my head is about to explode.

Thanks!

like image 759
Phil Avatar asked Nov 09 '09 13:11

Phil


2 Answers

It might be of use to look into the screencasts at BDDCasts.com. They walk you through creating the stories and specs for an app. It really helped me. Also own the rspec book, but was still confused. You might even want to just check out their source on github.

For me it goes like this:

  • Cucumber to test what the user will see. (Full stack test)

  • Rspec to test everything else. (Model, controller)

like image 145
coreypurcell Avatar answered Sep 19 '22 07:09

coreypurcell


Cucumber is used to explain (make a description) of a part (story) of the application rather than unit tests or behaviour tests (which is the focus of RSpec)

So, IMHO Cucumber tests (stories) do not substitute for RSpec tests.

The RSpec tests tend to drive development of the models and controllers, and the stories tend to drive development of the views.

From your description it seems like you are using cucumber to both test the stories and the behavior.

like image 27
Diego Dias Avatar answered Sep 22 '22 07:09

Diego Dias