Cucumber versus Spinach

Recently a friend was about to roll out Cucumber in his development team and told me about it. I told him that I moved from Cucumber to Spinach for several reasons. I guess this will help more people, so here they are:

  1. In Cucumber steps are implemented with regular expressions. Although that looks cool because it gives a lot of flexibility, it rapidly turns out that the regular expressions and the implementation of the steps become very complicated. A step implementation is often long. One is tempted to allow a lot of variation in the regular expressions, which yields overcomplicated and functionality-overloaded steps. Needless to say that maintenance of such steps is hard.
    Spinach does not use regular expressions. The steps are simpler and if you want to reuse functionality, you can use plain Ruby methods. Those methods can be grouped in a Ruby module and the module can be included in step classes for a feature. Doing so enables maximal reuse.
  2. Cucumber uses a global namespace for all steps. That is pretty annoying, certainly when the number of features and the number of steps is high.
    Spinach uses classes, so all steps of a feature are scoped to a class.
  3. There has been much discussion in the BDD community about the level of abstraction of steps. For instance, one could write a scenario like:
    Given I am logged in as normal user
    When I go to the page to edit my personal details
    And I fill in "First name" with "John"
    And I fill in "Last name" with "Doe"
    ...
    And I fill in "Yet another field" with "yet another input"
    And I press the save button
    Then I see a flash "Data saved succesfully"
    And I see "John" in "First name"
    And I see "Doe" in "last name"
    ...
    And I see "yet another input" in "Yet another field"

    while for maintenance reasons and for reasons of clearly communicating to other people what the behaviour of the application is, it is much better to write:

    Given I am logged in as normal user
    When I edit my personal details by filling in all fields
    Then I have saved my personal details successfully

    Of course this can be expressed like that in Cucumber too, but my experience is that the absence of regular expressions in Spinach helps to reach a better level of abstraction.

  4. Apart from the good stuff, there are probably some less positive sides to using Spinach, but I have not encountered them, except for one: the error reporting can be improved. In RSpec for instance, one gets a nice list of failing examples, together with the RSpec commands to run the failing examples. Spinach does not have that and I miss it. Maybe I should contribute to Spinach to improve that :-)

Canis Audacis sees the light

Welcome to Canis Audacis, Koen De Hondt’s blog on web development with Ruby on Rails, behaviour driven development, lean development and getting things done.

I have contributed to a few blogs before (see Code, the Universe and Everything and In the Cloud), but it is time to start a blog dedicated to my thoughts and experiences with web development in Ruby on Rails, using Spinach and RSpec, and many other technologies.

It has been a while since I wrote my last blog post, but for a very long time I feel that I need to write things down, not only to create an archive of what I have learned and what I have done, but also to help people with advice and solutions for their problems.