想要在运行 Cucumber 之前加载种子数据
我希望黄瓜在开始测试之前将我的种子数据加载到“db/seeds.rb”中。不是在每个场景或功能之前,而是在运行测试之前仅一次。 而且在每个场景之后,种子必须保留在数据库中。
这可能吗?
我尝试创建一个文件“features/support/seed_data.rb”并要求其中包含我的 db/seeds.rb,但似乎该文件根本没有加载。我试图在 env.rb 中要求我的种子 - 没有影响。
请问有人可以建议我解决方案吗?
提前致谢!
I want cucumber to load my seed data in "db/seeds.rb" before starting to test. Not before each scenario or feature, but only once before running the tests.
And also after each scenario, the seeds must remain in db.
Is that possible?
I've tried creating a file "features/support/seed_data.rb" and requiring my db/seeds.rb in there, but it seems that file is not loaded at all. I tried to require my seeds in env.rb - no affect.
Please, can anybody suggest me the solution?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 support/hooks.rb 文件中创建一个 before 钩子,如下所示:
在场景之前的测试中,像这样调用钩子:
Create a before hook in your support/hooks.rb file which looks like this:
In your test before the scenario, call the hook like this:
如何从 seeds.rb 文件中提取代码并将其粘贴到 AfterConfiguration 块中的 hooks.rb 中?
应该在运行期间、配置 Cucumber 后立即调用一次。至少这样做,您可以确定是否只是在包含种子文件时遇到问题。另一个想法是采用 seeds.rb 并将其作为模块直接粘贴到支持目录中,然后从 AfterConfiguration 调用它:
How about pulling the code from your seeds.rb file and sticking it in hooks.rb in an AfterConfiguration block?
That should be called once during a run, right after cucumber is configured. At least doing it this way, you can determine if you just have an issue with including your seeds file or not. Another idea would be to take seeds.rb and stick it directly inside the support directory as a module and then call it from AfterConfiguration: