【问题标题】:Why do I get 'Undefined dynamic step' in Cucumber?为什么我在 Cucumber 中得到“未定义的动态步骤”?
【发布时间】:2016-10-15 21:16:05
【问题描述】:

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

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'

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

谢谢

【问题讨论】:

    标签: ruby cucumber automated-tests


    【解决方案1】:

    在这一行:

      step %{When xxx the calculator is run xxx}
    

    删除“时间”,它应该可以正常工作。

    您可以在cucumber docs 中查看。他们给出的step 示例不包含“When”一词。

    【讨论】:

    • 是的,它有效,谢谢。我还注意到,如果我将“步骤”更改为“步骤”也可以。所以 step %{xxx 计算器运行 xxx}step "xxx 计算器运行 xxx"steps %{When xxx the calcualtor is run xxx} 都可以,但我用的一个不行。
    • 谢谢 - 我发现如果您使用 steps 进行动态表步骤,您还 碰巧 需要一个 When/And/Then 前缀。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    • 1970-01-01
    相关资源
    最近更新 更多