toms blog - the blog with the poorest subheadline

Artikel mit ‘cucumber’ getagged

Rails 3 in Action – Undefined Step Sonntag, 8. Januar 12

Hey, I´m writing this article in english this time, because I think it may also be useful for some people not familiar with the german language :)

Currently I´m playing around with the really good book “Rails 3 in Action” from Manning. It provides a good and easy to understand introduction in TDD and BDD. Unfortunately it refers to an older version of Cucumber (< 1.1), where a file called “web_steps.rb” was created. If you are trying to follow the books steps of chapter 3.2 (First steps), you will stumble upon the problem, that the current version of Cucumber doesn´t create this file.

Instead the rake cucumber:ok command raises following error:

Undefined step: "I am on the homepage"

The reason why web_steps.rb isn´t there anymore is described at large in this article.  I suggest you, to read this article and keep the thoughts made by the author in mind, when you want to build scenarios in the feature. However, to be able to follow this book, you can do it like I did:

Create a file called “project_steps.rb” under /features/step_defintions/ in your rails folder and add following code:


Given /^I am on the homepage$/ do
visit "/"
end

When /^I follow "([^"]*)"$/ do |link|
click_link link
end

When /^I fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
fill_in field, :with => value
end

When /^I press "([^"]*)"$/ do |button|
click_button(button)
end

Then /^I should see "([^"]*)"$/ do |content|
page.should have_content(content)
end

Then /^I should be on the project page for "([^"]*)"$/ do |name|
project_path(Project.find_by_name!(name))
end

With this file in place, you cal run rake cucumber:ok again and follow the steps as described in the book (at least for this chapter)

The second way to you can go is to install this additional gem: https://github.com/cucumber/cucumber-rails-training-wheels which seems to do nothing more, than to add the missing web_steps.rb. I´ve not tested it, though.

Hope you´re now back on the road rails again…