2

我正在用Rails中的黄瓜进行集成测试,我的所有场景都运行良好,但我需要在所有场景开始运行之前运行我的 db/seed.rb 文件中的种子,

我尝试在我的 support/env.rb 中添加这个:require File.dirname(__FILE__) + '/seeds'

但不起作用。

我怎样才能做到这一点?

谢谢 !

4

2 回答 2

4

关于是否应该或不应该为此使用种子有各种想法。

我想知道每个离散场景是否有效,它们之间没有相互作用。这可能会使套件花费更长的时间,但可以让您的测试确信另一个场景不会引起连锁反应。因此,我选择为此使用种子。

我有一个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
于 2013-11-15T14:30:14.220 回答
0

加入作品require_relative '../../db/seeds'features/support/env.rb

于 2013-09-25T08:20:00.297 回答