想要在运行黄瓜之前加载种子数据 [英] Want to load seed data before running cucumber
问题描述
我想让黄瓜在开始测试之前,在db / seeds.rb中加载我的种子数据。不是在每个场景或功能之前,而是在运行测试之前只有一次。
在每个场景之后,种子必须保留在db中。
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?
提前感谢!
推荐答案
在支持/ hooks.rb文件中创建一个before hook,如下所示: / p>
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
这样的钩子:
@load-seed-data @US49
Scenario: This is a scenario that needs seed data.
Given...
这篇关于想要在运行黄瓜之前加载种子数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!