Cucumber Webrat and Debugging Features

October 12, 2008

Debugging with Cucumber

Simple as putting a debugger statement in any steps file.

Note also that you can run just one feature at a time with cucumber using -l. See cucumber -h

Needed this when dealing with a problem with Restful Authentication forms. What I wanted to do was run the following story

Scenario: Anonymous user can create an account
  Given I am on the signup page 
  When I fill in "Login" with "My product name"   

However this kept on failing with

When I fill in "Login" with "My product name"  # features/steps//common_webrat.rb:17
      Could not find input "Login". (Test::Unit::AssertionFailedError)

Very puzzling as this sort of test works fine with Products. The matcher for this task is

When /^I fill in "(.*)" with "(.*)"$/ do |field, value|      
  fills_in(field, :with => value)

So I added a debugger and stepped into the code

When /^I fill in "(.*)" with "(.*)"$/ do |field, value|      
  fills_in(field, :with => value)   

After a bit of traipsing around I found out that webrat uses a library called hpricot to implement most of its functionality, and that it was working fine. However the restful_authentication forms were not so good. Turns out that the labels were not matching the fields in the forms.

Learnt quite alot from this

  1. More about how webrat works
  2. How to debug a failing step

Anyhow learnt how to debug a feature