Cucumber 和 Rspec 共享工厂女孩工厂
我正在使用 Cucumber 和 Rspec 围绕 Rails 设计一个测试,我想知道在 Cucumber 验收测试和 Rspec 单元测试之间共享 Factory Girl 工厂代码是否是一个好习惯。
如果这是良好的做法,那么哪里是放置 rspec 和黄瓜工厂的最佳中立位置。
多谢
I'm designing a test around rails using Cucumber and Rspec and I was wondering if it is good practice sharing the Factory Girl factory code between the Cucumber acceptance test and Rspec unit tests.
And if it is good practice where would be the best place neutral location to place the factories for rspec and cucumber.
Thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在任何您喜欢的地方使用工厂。我通常在 rspec 和我的 Cucumber 故事中使用它们。
工厂是固定装置的替代品。总的想法是能够正确阅读测试并摆脱“固定装置”地狱场景。
我认为如果你放在spec/factories 中就可以了,没有标准位置。但我通常将其放在我的spec文件夹中。无需为其使用单独的中立位置。
You can use factories anywhere you like. I generally use them in rspec and my Cucumber stories.
Factories are fixture replacements. General idea is to be able to right readable tests and move away from the "fixtures" hell scenario.
I think its fine if you place in spec/factories , there is no standard location. But I generally place it in my spec folder. No need to use a separate neutral location for it.
是的,不重复相同的工厂定义是一个很好的做法(如果它们是共享的......我会满足于应该有一些重叠)。一种方法是在项目中创建一个名为factories的新目录,然后将以下内容添加到您的rspec和cucumber配置中:
Yes, it is a good practice to not repeat the same factory definitions (if they are shared... which I would content there SHOULD be some overlap). One way to do this is to create a new directory in your project called factories and then add the following to your rspec and cucumber configurations: