我有一些種子數據(價格範圍)是相同的產品,開發,測試,並沒有改變。我需要我的測試數據庫中的數據來運行我的cuke測試。嘗試加載我的種子數據在Rails3 /水豚與黃瓜測試之前factory_girl
我在加載情景之前將我的種子數據加載到測試數據庫中,但它失敗。
我在我的功能/支持/ env.rb文件中的以下
# from http://www.andhapp.com/blog/2009/11/07/using-factory_girl-with-cucumber/
Before do
require 'factory_girl_rails'
# Dir.glob(File.join(File.dirname(__FILE__), '../../spec/factories/*.rb')).each {|f| require f }
Dir.glob(File.join(File.dirname(__FILE__), '../../db/seeds.rb')).each {|f| require f }
end
它加載以下文件:
# wipe out all previous data
Price.delete_all #is there a factory way of doing this?
# set defaults
Factory.define :price do |price|
price.id 1
price.price_range "$100"
end
# insert seed data
@price = Factory(:price, :id => 1, :price_range => "$100 - $500")
@price = Factory(:price, :id => 2, :price_range => "$500 - $1,000")
@price = Factory(:price, :id => 3, :price_range => "$1,000 - $1,000")
@price = Factory(:price, :id => 4, :price_range => "$10,000 - $100,000")
我收到以下錯誤信息:
Factory already defined: price (Factory::DuplicateDefinitionError)
/Library/Ruby/Gems/1.8/gems/factory_girl-1.3.3/lib/factory_girl/factory.rb:61:in `define'
/Applications/MAMP/htdocs/rails_testing/feedbackd/features/support/../../db/seeds.rb:16
/Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
/Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
/Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:227:in `load_dependency'
/Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
/Applications/MAMP/htdocs/rails_testing/feedbackd/features/support/env.rb:92
/Applications/MAMP/htdocs/rails_testing/feedbackd/features/support/env.rb:92:in `each'
/Applications/MAMP/htdocs/rails_testing/feedbackd/features/support/env.rb:92:in `Before'
有什麼想法?