I’m trying to learn Cucumber. After poking around a bit on SO I found a link to this tutorial. It was very helpful (and I recommend it highly!), but, for a beginner like myself, a couple of the early steps were opaque. I thought I’d explain these two pitfalls here, to spare future Cucumber students the head-scratching they caused me.
The two problems both came up in this section:
Starting the fail-fix cycle
I run it using cucumber features, and it fails on the first line –
Given I go to the new book page – because cucumber doesn’t know where
the “new book page” is. So I add that to the cucumber paths helper.when /the new book page/ new_book_path
I had trouble interpreting this section and running her code.
My first question was: where do I find the cucumber paths helper file?
Once I figured it out and ran cucumber features, I got a syntax error.
My second question was how do I debug the syntax error that her code raises? I’ve tried to answer these two questions below.
First Gotcha: where the heck is the `cucumber paths helper’?
First off, she talks about adding a step to the
cucumber paths helper. I struggled for a while to figure out where this file was located. I couldn’t find anything with a similar name in my app, and google searches didn’t yield any useful results. What was going on?It turns out that I couldn’t find the file because it’s not automatically generated — you need to create it yourself. Furthermore, the name of the file is totally arbitrary: it doesn’t need to be called
cucumber_paths_helper. That’s why my google searches were fruitless.For her code snippet to be executed it just needs to be in some file living in the
features/supportfolder. All of the code in this directory is executed before any cucumber tests are run. The solution? I put her code into a new file atfeatures/support/manage_books_steps.rb.Ok, one down…
Second Gotcha: syntax error, unexpected keyword_when
The next problem showed up when I tried to run
cucumber features. I got this:For some reason my system couldn’t parse this code. I’m not sure why exactly, but I’m guessing that Sarah was using some gem or tool to preprocess her code that I didn’t have installed, and she unfortunately didn’t go into detail about her gemset in the article. (Maybe she wrote it before cucumber’s training wheels came off?) In any case, after consulting some other cucumber tutorials I tried reformatting her snippet like so.
This worked.
After getting past those two little obstacles, the rest of the tutorial was a synch.
Anyway, I hope this helps someone somewhere down the line. And thanks, Sarah, for a great tutorial.
Edits/comments/corrections are welcome.