【问题标题】:Cucumber: Multiline arguments using "step" method inside a step definitionCucumber:在步骤定义中使用“step”方法的多行参数
【发布时间】:2012-01-24 19:12:33
【问题描述】:

factory_girl 黄瓜助手很酷。我喜欢这个工作:

Given the following users exist:
  | Name | Email            |
  | Alan | alan@example.com |
  | Bob  | bob@example.com  |

但我不知道如何在步骤定义中调用它们。例如:

Given /the usual users exist/ do
  step "the following users exist:
    | Name | Email            |
    | Alan | alan@example.com |
    | Bob  | bob@example.com  |"
end

...抛出Your block takes 1 argument, but the Regexp matched 0 arguments. (Cucumber::ArityMismatchError)

在步骤定义中使用step 将多行参数传递给另一个步骤的正确方法是什么?

编辑: 源代码总是很方便。我发现step 的签名是def step(name, multiline_argument=nil)。暗示性的。然而很遗憾,

step "the following users exist", "
    | Name | Email            |
    | Alan | alan@example.com |
    | Bob  | bob@example.com  |"

undefined method 'hashes' for #<Cucumber::Ast::DocString:0xa9bf6f4> (NoMethodError) 也会失败。我仍然很想知道它应该如何工作。

不过,也有一线希望。我找到了另一个函数steps,它是def steps(steps_text),它可以工作。查看答案。

【问题讨论】:

    标签: ruby-on-rails-3.1 cucumber factory-bot


    【解决方案1】:

    这不是我想要的,但阅读源代码会发现以下工作:

    Given /the usual users exist/ do
      steps "Given the following users exist:
        | Name | Email            |
        | Alan | alan@example.com |
        | Bob  | bob@example.com  |"
    end
    

    【讨论】:

    • @JustinSearls - 非常适合我,在过去的一年里一直如此。
    猜你喜欢
    • 1970-01-01
    • 2017-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多