More Cucumber Common Steps and Love

You just have to love this “syntax” 😀

Scenario: I add to an discussion
    Given I am logged in
    And a "Discussion" exists for "Festival" "1"
    And I am on "Festival" "1"
    When I fill in "Text" with "Halloo"
    And I press "Send"
    Then I should be on "Festival" "1"
    And I should see "Halloo"


# On page/record
Given /^I am on "([^"]*)"$/ do |path|
  visit path

Then /^I should be on "([^"]*)"$/ do |path|
  current_path.should == path

Given /^I am on "([^"]*)" "([^"]*)"$/ do |model,number|
  visit polymorphic_path(record_from_strings(model,number))

Then /^I should be on "([^"]*)" "([^"]*)"$/ do |model,number|
   current_path.should == polymorphic_path(record_from_strings(model,number))

# Existing
Given /^a "([^"]*)" exists for "([^"]*)" "([^"]*)"$/ do |associated,model,number|
  record = record_from_strings(model,number)

# Login
Then /^I should be logged in$/ do
  should be_logged_in

Given /^I am logged in$/ do
  visit 'login'
  fill_in 'email', :with=>''
  fill_in 'password', :with=>'test'
  click_button 'Login'

# Support
def current_path

def record_from_strings(model,number)


#load all fixtures
include AuthenticatedTestHelper #restful_authentification
include ValidAttributes #

7 thoughts on “More Cucumber Common Steps and Love

  1. yes, for simple cases i could,
    but if want to have an additional
    /^I am on “([^”]*)” “([^”]*)”$/ then “(.*)” would match –“a”– and –“a” “1”–
    Since the (.*) is greedy and grabs –a” “1–

  2. /I am on “(.*)” “(.*)”/ does match ‘I am on “a” “1”‘. The first match is “a” and the second match is “1”. The greediness doesn’t matter since the regexp has to match all four quotes.

  3. yes thats true but the problem i am trying to solve is that then simple form also matches the Then I should be on “Festival” “1”
    and when 2 ‘Then’s match –> exception

    so we are both right 😉

    (.*) can be used for the complex form (Then I should be on “Festival” “1”) but ([^”]*) has to be used for the simple form

  4. Ah, I think I understand. Just to be sure, you’re saying that the problem is if you have

    /I am on “(*.)”/


    /I am on “(*.)” “(*.)”/

    then they’ll both match

    ‘I am on “Festival” “1”‘

    and having two possible matches will produce a Cucumber error. Thanks!

Leave a Reply to pragmatig Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s