Cucumber:使用“step”的多行参数步骤定义内的方法
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这并不完全是我想要的,但阅读源代码表明以下内容有效:
It's not quite what I was looking for, but reading the source code reveals that the following works: