为什么我在 Cucumber 中得到 'Undefined dynamic step'?

Why do I get 'Undefined dynamic step' in Cucumber?

我有以下步骤定义(只是为了说明我的问题):

When(/^the calculator is run$/) do
  step %{When xxx the calculator is run xxx}
end

When(/^xxx the calculator is run xxx$/) do
  @output = `ruby calc.rb #{@input}` 
  raise('Command failed!') unless $?.success?
end

在我的功能文件中,当我调用时:

When the calculator is run

我收到错误消息:

Undefined dynamic step: "When xxx the calculator is run xxx" (Cucumber::UndefinedDynamicStep)
./features/step_definitions/calculator_steps_when.rb:2:in `/^the calculator is run$/'
features/adding.feature:11:in `When the calculator is run'
features/adding.feature:6:in `When the calculator is run'

根据文档,这应该可行。最初我有不同文件中的步骤,并认为也许我必须提供一些 include 指令,但现在即使步骤在同一个文件中也会发生。我错过了什么?

谢谢

这一行:

  step %{When xxx the calculator is run xxx}

删除 "When" 它应该可以正常工作。

您可以在 cucumber docs 中查看。他们给出的 step 示例不包含单词 "When".