[rspec-users] it "should [action] ..." vs it with an active voice

Wincent Colaiuta win at wincent.com
Tue Nov 13 04:59:55 EST 2007

(Coming in a little late on this thread...)

Although I use "should" in basically all of my examples I share some  
of Brian's objections to it. IMO, the strongest argument against it is  
that it is repetitive, and the strongest argument in its favor is that  
it perfectly captures the discrepancy between expected and actual  
behaviour in the case of failed or pending examples.

In an ideal world we'd be able to omit all those "shoulds", avoiding  
the repetition, and have RSpec automatically add them back in when  
needed (like when outputting failed or pending examples).

In other words, we'd be able to write things like:

   it 'returns true if other has the same length'

And in the case of a failed or pending example have RSpec  
automatically convert this to:

   'should return true if other has the same length'

This would require some sort of intelligent heuristic along the lines  
of wait Rails does with pluralization using inflectors. I am not sure  
if this is realistic, as the grammar involved goes somewhat beyond  
what's required by simple pluralization.

In most cases, like the one above, examples take the form of "should  
[verb]" and would need to be transformed into "[verb]+s".

Slightly more complicated are verbs in the passive voice:

   "should be substituted into the output"

Would become:

   "is substituted into the output"

Or cases like this one:

   "should be able to round trip"

Whose counterpart is:

   "can round trip"

Trickier are ones where "should" is not the first word in the example.  
Looking in my own specs I occasionally have ones worded like this:

   "line and column end should reflect last succesfully scanned  
position prior to failure"

This one highlights a potential problem: that any automated  
translation would impose strict requirements on the form that examples  
could take, and the loss in flexibility may make it not worth it (in  
the example above I would have to move the "line and column end" up  
into the "describe" parameter, and doing that would require me to  
split the existing block up into two separate blocks). It's clear that  
there will be cases in which the freedom to write flexible "it"  
parameters will make your specs more natural, readable, and less  

Another problem, this would (obviously) only work for English.

Anyway, just an idea to throw out there.


More information about the rspec-users mailing list