ruby cucumber - 步骤未定义消息但步骤存在于 step_definitions

ruby cucumber - step undefined message but step exists in step_definitions

我目前在 运行 我的 BDD 脚本期间收到一条不寻常的错误消息,当我通过命令行 运行 时收到以下响应:

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

(箭头中的那个是在我的命令行中突出显示为未定义的那个)

但是,在 step_definitions 文件夹下的 .rb 脚本中,我有以下内容:

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

我不确定为什么这个黄瓜脚本会漏掉一个步骤,但这让我很生气。有人可以帮忙吗?

编辑:除此之外,如果有人也能回答为什么它没有向我显示它期望的片段,那就太好了。

由于您的正则表达式与您的文本不匹配,您收到了缺少步骤定义错误。

你想要的是:

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

它将匹配文字字符 + 而不是 B 一次或多次。

记住,ruby-cucumber 使用正则表达式语法而不是文字字符串来匹配 step-defs。

您不应为每个计划创建一个步骤。

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