2013-09-21 92 views
2

我正在做一個與黃瓜的​​集成測試rails我已經有了我所有的場景都可以正常工作,但是我需要的是我之前運行的db/seed.rb文件上的種子所有的場景開始運行,在黃瓜試運行之前運行種子 - 導軌3.2

我嘗試添加這在我的支持/ env.rb:require File.dirname(__FILE__) + '/seeds'

但does'n工作。

我該怎麼做?

謝謝!

+0

這不是種子是:/ – sevenseacat

回答

0

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

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