Raisus
Raisus

Reputation: 169

ruby cucumber - step undefined message but step exists in step_definitions

I'm currently getting an unusual error message in that during the run of my BDD scripts, I get the following response when running through the command line:

Feature: As a user I want to purchase a mobile on a monthly plan
@ACQ_Test_01

  Scenario: Buy a pay monthly phone
    Given I am on the Store Homepage
    When I click on the Mobile Phones roundel link
    And I select a "Apple" "Iphone 6s"
    -->And I select the "1GB+AYCE min" price plan<--
    Then I can complete my order

1 scenario (1 undefined)
5 steps (1 skipped, 1 undefined, 3 passed)
0m0.130s

(The one in arrows is the one highlighted in my command line as being undefined)

However, in my .rb script under step_definitions folder, I have the following:

Given (/^I am on the Store Homepage$/) do
  **CONTENT-HERE**
end
When (/^I click on the Mobile Phones roundel link$/) do
  **CONTENT-HERE**
end
When (/^I select a "Apple" "Iphone 6s"$/) do
  **CONTENT-HERE**
end
When (/^I select the "1GB+AYCE min" price plan$/) do
  **CONTENT-HERE**
end
Then (/^I can complete my order$/) do
  **CONTENT-HERE**
end

I'm not sure why this cucumber script is missing out a step, but it's infuriating me to no end. Can anyone help?

EDIT: Off the back of that, if anyone can also answer why it's not showing me the snippets that it's expecting, that'd be great.

Upvotes: 0

Views: 336

Answers (2)

Dave McNulla
Dave McNulla

Reputation: 2016

You should not be creating a step for each plan.

When (/^I select the "([^"]*)" price plan$/) do |plan|
  case plan
  when "1GB+AYCE min"
    # do something
  end
end

Upvotes: 2

Sebastian Lenartowicz
Sebastian Lenartowicz

Reputation: 4854

You're getting a missing step-def error because your regex isn't matching your text.

What you want is:

When (/^I select the "1GB\+AYCE min" price plan$/) do

Which will match the literal character + rather than B one or more times.

Remember, ruby-cucumber uses regular expression syntax rather than literal strings to match step-defs.

Upvotes: 0

Related Questions