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:
- 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.
- 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.
- 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.
- 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