2015-11-20 46 views
8

我已經安裝了工廠女孩,並試圖與規範一起使用它。未定義的方法`創建'軌道規範。

scenario 'User signs in' do 
    create :user, email: '[email protected]', password: 'testpassword' 
    visit '/users/sign_in' 

    fill_in 'Email', with: '[email protected]' 
    fill_in 'Password', with: 'testpassword' 
end 

我收到以下錯誤消息。

Failure/Error: create :user, email: '[email protected]', password: 'testpassword' 
NoMethodError: 
    undefined method `create' for #<RSpec::ExampleGroups::UserSignIn:0x007fe6324816b8> 
+1

嘗試'FactoryGirl.create' –

回答

7

在我來說,我錯過了config.include FactoryGirl::Syntax::Methodsrails_helper.rb

5

我們可以在factory_girl's documentation找到解決方案:

1)創建文件/spec/support/factory_girl.rb

RSpec.configure do |config| 
    config.include FactoryGirl::Syntax::Methods 
end 

2)編輯/spec/rails_helper.rb加載的所有文件中支持目錄:

Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } 
相關問題