想在运行黄瓜之前加载种子数据 [英] Want to load seed data before running cucumber

查看:20
本文介绍了想在运行黄瓜之前加载种子数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望黄瓜在开始测试之前将我的种子数据加载到db/seeds.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.

这可能吗?

我尝试创建一个文件features/support/seed_data.rb"并在其中要求我的 db/seeds.rb,但似乎根本没有加载该文件.我试图在 env.rb 中要求我的种子 - 没有影响.

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?

提前致谢!

推荐答案

在你的 support/hooks.rb 文件中创建一个 before 钩子,如下所示:

Create a before hook in your support/hooks.rb file which looks like this:

Before('@load-seed-data') do
  load File.join(Rails.root, 'db', 'seeds.rb')
end

在场景之前的测试中,像这样调用钩子:

In your test before the scenario, call the hook like this:

@load-seed-data @US49
Scenario: This is a scenario that needs seed data.
Given...

这篇关于想在运行黄瓜之前加载种子数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆