ruby-on-rails - 在 cucumber 测试运行之前运行种子 - Rails 3.2

标签 ruby-on-rails ruby cucumber

我正在使用 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/

相关文章:

ruby-on-rails - Rails 控制台不会加载,因为扩展尚未构建。有任何想法吗?

Ruby - 递归地哈希到方法

python - 如何使用beeve(Python BDD框架)设置环境变量?

python - 集成 Rails 和 Python

ruby-on-rails - 如何 stub 事件记录关系以使用 rspec 测试 where 子句?

android - Cucumber 测试未按指定顺序运行,出了什么问题?

maven - 当文件存在时使用通配符激活配置文件

ruby-on-rails - 在 ruby​​ 中一次移动所有具有相同扩展名的文件

ruby-on-rails - rails : Your user account isn't allowed to install to the system RubyGems

ruby-on-rails - rspec/guard 运行 minitest 并获取无效选项 : -f