[LRUG] Writing readable feature tests with RSpec

Sam Livingston-Gray geeksam at gmail.com
Fri Jul 25 12:32:21 PDT 2014


On Fri, Jul 25, 2014 at 4:11 AM, Tom Stuart <tom at codon.com> wrote:

> On 25 Jul 2014, at 11:41, Najaf Ali <ali at happybearsoftware.com> wrote:
> > /switches on Tom Stuart bat signal
>
> :-)
>

Does responding to this make me Robin to Tom's Batman?  If so, so be it.
 (Tom, you may send me a cape and mask at your leisure.)

I just read Joel's blog post at the top of this thread.  Ironically, the
same solution that the post suggests for RSpec also works perfectly well in
Cucumber.  In fact, that approach is probably the only way to maintain any
sort of sanity in Cucumber.  It's also recommended in
http://pragprog.com/book/hwcuc/the-cucumber-book, but if anything I think
that book doesn't quite go far enough.

One of the fundamental problems with Cucumber, I think, is that so many
people come away from our introduction to Cucumber thinking that because
Cucumber is implemented by attaching blocks to regular expressions, *that's
the only tool we have to organize the implementation of our step
definitions*.  I'm definitely included in that statement:  it took me years
to get to the point where the majority of my step definitions are
one-liners that call out into some other layer of software.

Obviously, "add another layer!" is unlikely to appeal to those who think
Cucumber already adds too many, but as with all technologies, there are
tradeoffs involved.  On the one hand, Cucumber is necessarily a bit further
removed from your code, which adds implementation costs.  On the other
hand, that is *exactly the point* of using Cucumber!  As Tom so aptly said,
it's a mind hack.  The benefit (IMO) is that Cucumber offers you a
different way of thinking about the behavior of your system.

In some cases, the benefit may not outweigh the costs—but I humbly suggest
taking a closer look at both, because while it's very easy to make a huge
mess with Cucumber, it's also possible for diligent developers to minimize
its implementation costs.  And I see significant benefits to the Gherkin
DSL, especially, that make it seem like the baby that gets thrown out with
Cucumber's bathwater.

Another factor may be that Cucumber offers several different kinds of
benefits at different levels of an organization and on different time
scales, but those benefits only outweigh the costs *in aggregate* and over
time, making it too easy to fixate on a single aspect and decide "it's just
not worth the bother."  Curious readers should refer to
http://rubyrogues.com/077-rr-complexity-with-glenn-vanderburg/.  There's no
#bookmark to it, so you'll have to search for where Glenn says "Somebody
mentioned unit testing" and read the following two paragraphs.

Anyway, back to work.  (I hope to have considerably more to say on this
topic soon.)

-Sam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20140725/65b2104a/attachment.html>


More information about the Chat mailing list