Cucumber:引用/不引用参数的最佳实践是什么
在 Cucumber 中,您可以定义定义 BDD 语法的步骤;例如,您的测试可能有:
When I navigate to step 3
然后您可以定义一个步骤:
When /^I navigate to step (\d+)$/ do |step_number|
# navigate to step ${step_number}
end
现在,上述所有内容都可以正常工作(或者至少我认为可以)。但是,您也可以这样做:
When I navigate to step "3"
使用正则表达式:
When /^I navigate to step "(\d+)"$/ do |step_number|
在“The RSpec Book: Behaviour-Driven Development with Rspec, Cucmber, and Friends”中,作者 David Chelimsky 写道“步骤有两种常见样式......讨论优点以及与你的团队的意见”。在我的团队中,一些人已经开始使用引号,但这使得手动调用步骤更加尴尬,因为您必须转义步骤步骤名称中的引号(当这些步骤名称本身包含在引号中时)。但是,使用引号可以更清楚地显示变量在 Cucumber 文本中的位置。
所以,我想知道的是:社区对于什么是“正确”的风格有任何共识吗?或者缺少那个......
- 有没有人做过两种风格之间的好处比较?
- 有人广泛使用过这两种风格吗?
理想情况下,我希望在我们用“错误”风格编写一百万个测试之前尽可能多地了解情况;-)
In Cucumber you define steps which define your BDD syntax; for instance, your test might have:
When I navigate to step 3
and then you might define a step:
When /^I navigate to step (\d+)$/ do |step_number|
# navigate to step ${step_number}
end
Now, all of the above works perfectly fine as is (or at least I think it does). However, you can also do this instead:
When I navigate to step "3"
with a regex:
When /^I navigate to step "(\d+)"$/ do |step_number|
In "The RSpec Book: Behaviour-Driven Development with Rspec, Cucmber, and Friends", author David Chelimsky writes "There are two common styles for steps ... Discuss the pros and concs with your team". On my team a few people have already started using quotes, but it makes invoking steps manually more awkward because you have to escape the quotes inside the step step names (when those step names are themselves wrapped in quotes). However, having quotes makes it more clear where variables are in the Cucumber text.
So, what I'm wondering is: is there any sort of community consensus on what the "right" style is here? Or lacking that ...
- Has anyone ever done a benefit comparison between the two styles?
- Has anyone used either style extensively?
Ideally I'd like to find out as much as I can before we write a million tests with the "wrong" style ;-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看到没有人回复你,我决定发表评论 - 也许你会发现我的意见有帮助。
例如,我在一个项目中广泛使用了这两种风格,在这个问题上没有“应该这样做”。我想我更多地结束了使用“(\d+)”风格,因为,就像你说的:
至于构建由其他步骤组成的步骤,我通常这样做:
希望有所帮助,我愿意讨论:)
Seeing as no one is replying to you, I decided to comment - maybe you'll find my opinion helpful.
For example I've been using both styles extensively on a project where there was no "should do this way" in this matter. I think I ended using "(\d+)" style more, because of, like you said:
As for constructing steps that are composed of other steps, I usually did:
Hope that helps, I am open for discussion :)