菠菜与黄瓜在 Rails 中的 BDD
我开始学习 BDD。想知道从黄瓜或菠菜开始哪个更好。我的印象是菠菜是新鲜的。看看这里
哪一个我应该从.标准是——
- 全面支持。
- 使用灵活性
- 第三方工具和 API 集成。
这可能又是新手无知的问题:水豚适合图片中的什么位置。
I am starting on BDD. Was wondering which would be better to start with Cucumber or Spinach. My impression is that Spinach is new off the block. Look here
Which one should I start with. The criteria would be -
- Support across the board.
- Flexibility of use
- Third party tool and APIs integration.
Again it might be ignorant question of the newbie: Where does capybara fit into the picture.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在某些情况下,我一直是黄瓜的长期用户,但从第一天起就一直希望它是菠菜。尽管有缺点,我还是将所有项目都转向了 Spinach,因为它使用了新的、现成的 PORO 技术(Plain Old Ruby Objects;)。现在我可以随心所欲地扩展我的步骤,因为它只是 Ruby。
为了回答您的问题,截至撰写本文时:
Cucumber
Spinach 仍在开发一些功能,包括“背景”块,我目前正在尝试让它识别表格。
菠菜
黄瓜从一开始就鼓励错误的步骤设计,IMO。如果您创建特定于功能的步骤,您稍后会遇到它们,如果您创建可重用的全局步骤,您的功能定义将会很长、通用且读起来很无聊。我听说人们声称他们可以成功地平衡,并且足够具体,但仍然有可重复使用的步骤;我认为自己足够精通,如果我不能可靠地做到这一点,那就太难了。
Cucumber,假设要点可以解释为社区。
如果您真正追求的是“第三方工具和 API 集成”,Spinach 支持 capybara 和 rspec,这就是您所追求的大部分内容。 Cucumber 有第 3 方可重用步骤库,但正如我之前指出的那样,我认为这很糟糕。关于第 3 方和集成,即使它还不存在,你也确实无法比普通的旧红宝石对象更好。
水豚是您网站的测试界面,又名测试鼠标和测试鼠标。键盘。您可以在控制台中启动它并驱动您的应用程序,但这会变得重复。黄瓜/菠菜(或 rspec/test-unit/minitest)都可以使用水豚来自动测试您的应用程序。人们更喜欢黄瓜/菠菜,因为它们可以帮助您跳出代码,像用户一样思考。
总的来说,你可能最好买一本 rspec/cucumber 书并按照它所说的去做。请注意,测试需要一段时间才能熟练,所以不要就此止步。也许在这个过程中的某个地方检查一下菠菜;如果您喜欢黄瓜,您可能会发现自己真的很喜欢菠菜。
For some context, I've been a long time user of Cucumber, but always wished it was Spinach since day one. I'm switching all my projects to Spinach despite its shortcomings because it uses the new, hot-off-the-block PORO technique (Plain Old Ruby Objects ;). Now I can expand my steps however I want, because it's just Ruby.
To answer your question, as of this writing:
Cucumber
Spinach is still developing some features, including 'Background' blocks, and I'm currently trying to get it to recognize tables.
Spinach
Cucumber encourages bad step design from the start, IMO. If you create feature-specific steps, you'll trip over them later, and if you create reusable global steps, your feature definitions will be long, generic, and boring to read. I've heard people claim they can walk a balance successfully and be just specific enough but still have reusable steps; I consider myself well versed enough that if I can't do it reliably, it's too hard.
Cucumber, assuming the bullet point could be interpreted as community.
If it's really "third party tools and API integration" you're after, Spinach supports capybara and rspec, which is most of what you're after. Cucumber has 3rd party reusable step libraries, but as noted in my earlier point, I think this is bad. In regard to 3rd party & integrations, even if it's not there yet, your really can't get any better than plain old ruby objects.
Capybara is your test interface to your site, aka a testing mouse & keyboard. You could start it up in a console and drive your app, but that'd get repetitive. Cucumber/Spinach (or rspec/test-unit/minitest) all could use capybara to automate testing your app. People prefer Cucumber/Spinach because they help you step out of the code for a bit to think like a user.
Overall, you'd probably be best off getting an rspec/cucumber book and doing what it says. Just be aware that testing takes a while to get good at, so don't stop there. Maybe check out Spinach somewhere in the process; if you like Cucumber, you might find you'll really like Spinach.
免责声明:我是一名菠菜管理员。
如果您从 BDD 开始,我强烈推荐两本书:
我认为学习所有 BDD 和 TDD 过程(由外向内等)然后选择很重要你感觉到的工具更舒服。
话虽如此,Cucumber 拥有一个庞大的社区,但很多东西也适用于 Spinach,因为它们的共同点是 Gherkin。
至于使用的灵活性,我想说两者都非常灵活,但我(显然)更喜欢 Spinach,因为它的每个功能都只是一个 Ruby 类,您可以在其中包含模块、从其他类继承等等(这也适用于 API 集成) 。
如果您愿意,您可以查看 spinach-rails-demo 并了解一切是如何工作的。
DISCLAIMER: I'm a Spinach mantainer.
If you're starting with BDD I'd highly recommend two books:
I think it's important to learn all the BDD and TDD process (outside-in etc..) and then choose the tool you feel more comfortable with.
Having said that, Cucumber has a huge community, but a lot of things are also aplicable to Spinach, since what they have in common is Gherkin.
As for flexibility of use I would say both are really flexible, but I (obviously) prefer Spinach as every feature it's just a Ruby class, where you can include modules, inherit from other classes and so on (this also applies to APIs integration).
I you want, you can take a look at the spinach-rails-demo and see how everything works.
如果您无法使用 Cucumber 并且不需要全局步骤,则可以通过使用某种场景 ID 标记步骤来解决该问题:
#1 场景 ID 可以是任何值。我喜欢使用票号以供将来参考。
然后,您可以将所有步骤放入一个步骤定义文件中。它与 Spinach::FeatureSteps 的外观足够接近。也没有正则表达式参数!
我在 github 上发布了有关解决方法的更多信息。
If you're stuck with Cucumber and you don't want global steps, you can work around the problem by tagging the steps with some sort of scenario ID:
The #1 scenario id can be any value. I like to use ticket numbers for future reference.
You can then place all the steps in one step definition file. It's close enough to the look of Spinach::FeatureSteps. No regex arguments too!
I posted more about the workaround at github.
我不能真正代表 Spinach,因为我从未使用过它,但 Cucumber 确实拥有巨大的社区支持和大量外部库。
Capybara 让您轻松测试 Web 应用程序
I can't really speak for Spinach, as I've never used it, but Cucumber definitely has a huge community support with loads of external libraries.
Capybara allows you to easily test web applications