Cucumber:使用“step”的多行参数步骤定义内的方法

发布于 2024-12-28 14:47:25 字数 1784 浏览 0 评论 0原文

Factory_girl 黄瓜帮手很酷。我喜欢它的工作原理:

Given the following users exist:
  | Name | Email            |
  | Alan | [email protected] |
  | Bob  | [email protected]  |

但我无法弄清楚如何在步骤定义中调用它们。例如:

Given /the usual users exist/ do
  step "the following users exist:
    | Name | Email            |
    | Alan | [email protected] |
    | Bob  | [email protected]  |"
end

... throws 您的块采用 1 个参数,但 Regexp 匹配 0 个参数。 (黄瓜::ArityMismatchError)

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

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

step "the following users exist", "
    | Name | Email            |
    | Alan | [email protected] |
    | Bob  | [email protected]  |"

#的未定义方法“哈希”也失败了。 (无方法错误)。我仍然很想知道这应该如何运作。

然而,还有一线希望。我发现了另一个函数 steps,它是 def steps(steps_text),并且可以工作。查看答案。

The factory_girl Cucumber helpers are cool. I love that this works:

Given the following users exist:
  | Name | Email            |
  | Alan | [email protected] |
  | Bob  | [email protected]  |

But I can't work out how to invoke them inside a step definition. For instance:

Given /the usual users exist/ do
  step "the following users exist:
    | Name | Email            |
    | Alan | [email protected] |
    | Bob  | [email protected]  |"
end

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

What's the correct way to pass a multiline argument to another step using step inside a step definition?

Edit:
Source code's always handy. I found that the signature for step is def step(name, multiline_argument=nil). Suggestive. Sadly, however,

step "the following users exist", "
    | Name | Email            |
    | Alan | [email protected] |
    | Bob  | [email protected]  |"

also fails with undefined method 'hashes' for #<Cucumber::Ast::DocString:0xa9bf6f4> (NoMethodError). I'd still love to know how that's supposed to work.

However, there's a silver lining. I found another function steps, which is def steps(steps_text), and that works. See answer.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

转身以后 2025-01-04 14:47:25

这并不完全是我想要的,但阅读源代码表明以下内容有效:

Given /the usual users exist/ do
  steps "Given the following users exist:
    | Name | Email            |
    | Alan | [email protected] |
    | Bob  | [email protected]  |"
end

It's not quite what I was looking for, but reading the source code reveals that the following works:

Given /the usual users exist/ do
  steps "Given the following users exist:
    | Name | Email            |
    | Alan | [email protected] |
    | Bob  | [email protected]  |"
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文