Being careful with Cucumber step names

Today I had an interesting problem with Cucumber the step “I sign in” was being called when my feature file had “When I sign in to the ….”.

The step looked like this:

When /I sign in/ do
    visit “/signin”

    …
end

Turns out, this is actually acceptance – and nice behaviour! The reason is because the regex doesn’t state start end characters, as such it would make to any step with the text “I sign in”

Why is it nice? Well I also had two step definitions called

Given I do something
And I do something again

Both did exactly the same thing, but to make the feature more readable I added the again word. Sadly the implementation looked something like this with the step being duplicated.

Given /^do something again$/ do
  Given ‘do something’
end

With the trick above, I could simply have the step below which would be called with and without the again word.

Given /^do something/ do
   # Work goes here.

end

Simple, but effective.

Installing Cucumber 0.8.5 fails due to gherkin not installed

This morning I was attempting to install the latest version of Cucumber, however I recieved an error saying gherkin (the language parser of the tests) was not installed.

C:>gem install cucumber –no-ri –no-rdoc
ERROR:  Error installing cucumber:
        cucumber requires gherkin (~> 2.1.4, runtime)

Generally, gems install all of the dependencies so I found this a little bit strange. Naturally, I manually install it.

C:>gem install gherkin –no-ri –no-rdoc
Successfully installed gherkin-2.2.0-x86-mswin32
1 gem installed

Sadly, this still didn’t work. The reason was it needs 2.1.4 installed, not the 2.2 version.

Executing the following allowed me to install Cucumber as normal

gem install gherkin –version 2.1.4 –no-ri –no-rdoc