[LRUG] Cucumber and RSpec on Rails

Joseph Wilk joe at josephwilk.net
Tue Feb 9 01:42:55 PST 2010


On 08/02/2010 19:42, Jordi Noguera Leon wrote:
 > Hi there!
 >
 > I'm starting with Cucumber but I'm not sure if/when/how to create 
specs. In the couple of Railscasts I'seen so far, the guy generates 
rspec_models and rspec_controllers, but he doesn't code anything inside 
them... In another screencast I've seen, the guy validates uniqueness of 
some stuff inside the spec, but I guess that's something you could do 
using a  scenario, right? Basically, do I need to write any spec or I 
can do all the stuff in the scenario?

Hello,

While there is not a fit all rule, it comes down to considering a couple 
of points:

1. Complexity/Distance/Focus
The scenario focuses on the real value realised by the system (the 
output), there can often be quite a distance between the implementation 
and the output. Hence you're failing feature might leave you very 
stumped as to what is wrong/what to do next. You may also have complex 
logic that you feel like needs more developer focused tests and feedback 
(a tighter feedback loop). In these cases specs can help you out.

2. Speed
In Cucumber we try and exercise the entire application stack and avoid 
mocking where possible. As a consequence things can get slow. If running 
a cucumber scenario takes 4/5 minutes that could significantly slow down 
your development cycle (While it still as a test has a lot of value 
testing everything interacts nicely). Hence you might drop down to a 
spec and stub out an area of the system to help achieve faster feedback 
(not that is the only reason to stub, it all helps achieve focus as we 
can isolate from the other systems we don't care about.)

3. Fragility
In my experience Features/Cucumber tend to live longer than specs. When 
I have performed major refactoring some of the specs tended to be thrown 
away while the features stuck around (the step defs may however have 
changed). That does not mean the specs weren't useful, just something to 
think about.

4. Personal taste
Some people Just Cuke, some people just spec and some people do both.
For me personally I use both, that does not mean its the right way for 
you. Play around and get a feel for how you want to use these tools.

HTH
--
Joseph Wilk
http://blog.josephwilk.net
+44 (0)7812 816431


 >
 > Regards,
 > Jordi
 >
 >
 > _______________________________________________
 > Chat mailing list
 > Chat at lists.lrug.org
 > http://lists.lrug.org/listinfo.cgi/chat-lrug.org





More information about the Chat mailing list