2016-01-21 45 views
1

我已經通過這些頁面了,並試圖在這些網頁上發現了許多東西:FactoryGirl:工廠未註冊的發動機項目

FactoryGirl: Factory not registered: user (ArgumentError) Cannot get factory_girl running under rails 3.0.5,unexpected tCONSTANT 'Factory not registered' error in Rails 4 FactoryGirl: Factory not registered

但總是收到「工廠未註冊:用戶「

文件test/factories.rb(也試過test/factories/user_factory.rb)看起來像:

FactoryGirl.define do 
    factory :user do 
    login '[email protected]' 
    email '[email protected]' 
    end 
end 

存根測試:

it 'just_a_test_of_testing' do 
    u = FactoryGirl.create(:user) 
    end 

不工作,給了我 「引發ArgumentError:工廠未註冊:用戶」

有誰知道 「正確的解決方案」?看起來它可能與「引擎」有關,但我不知道接下來要嘗試什麼,有什麼想法?也許這與用戶是測試/虛擬應用模型的事實有關?

回答

0

您是否在spec/support/factory_girl.rb文件中配置了定義路徑爲FactoryGirl documentation建議?

FactoryGirl.definition_file_paths = %w(custom_factories_directory) 
FactoryGirl.find_definitions 
+0

該文件不存在;如果我創建它並添加它,它似乎沒有影響。我曾嘗試爲引擎和應用程序創建它 – Gerry

0

的同事,得到了它去,他的課貌似

Module MyEngineMod 
    FactoryGirl.define do 
    factory :user, class: User do 
     # content not shown 
    end 
    end 
end 

所以,現在看來,這至少需要進行命名空間的,也許需要等級:屬性太。