2017-02-24 26 views
0

這裏是一個工作代碼:使用定義沒有出廠

FactoryGirl.define do 
    factory :address, class: 'Address' do |a| 
    #... 
    end 
end 

我要調用的方法define沒有factoryGirl

我嘗試這樣做:

include FactoryGirl::Syntax::Methods 

define do 
    factory :address, class: 'Address' do |a| 
    #... 
    end 
end 

,我得到一個錯誤:

NoMethodError: undefined method `define' for main:Object 

有沒有什麼解決辦法嗎?

回答

1

包括the proper module將使其工作(一,其中define定義):

include FactoryGirl::Syntax::Default