我正在使用 cucumber 在 rails 中进行集成测试,我的所有场景都运行良好,但我需要在所有场景开始之前运行 db/seed.rb 文件上的种子运行,
我尝试将其添加到我的 support/env.rb 中:require File.dirname(__FILE__) + '/seeds'
但不起作用。
我该怎么做?
谢谢!
最佳答案
关于是否应该为此使用种子有多种想法。
我想知道每个离散场景是否有效,并且它们之间没有相互作用。这可能会使套件花费更长的时间,但可以让您的测试充满信心,确保其他场景不会导致链式 react 。因此,我选择使用种子。
我有一个support/seeds.rb
,其内容为:
Before do |scenario|
load Rails.root.join('db/seeds.rb')
end
请注意,您可能希望将其与以下内容结合起来:
begin
# start off entire run with with a full truncation
# DatabaseCleaner.clean_with :truncation, {:except => %w[plans]}
DatabaseCleaner.clean_with :truncation
# continue with the :transaction strategy to be faster while running tests.
DatabaseCleaner.strategy = :transaction
rescue NameError
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end
关于ruby-on-rails - 在 cucumber 测试运行之前运行种子 - Rails 3.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18934317/