railstutorial.org - undefined method `Factory'

前端 未结 10 1407
时光取名叫无心
时光取名叫无心 2021-02-14 08:06

I\'m attempting to follow railstutorial.org, and am currently on Chapter 7, where you start using factories: http://railstutorial.org/chapters/modeling-and-viewing-users-two#sec

相关标签:
10条回答
  • 2021-02-14 08:38

    I have done so, add require 'factory_girl' to test_helper.rb and

    @user = FactoryGirl.create(:user)
    
    0 讨论(0)
  • 2021-02-14 08:47

    In your spec use

      @user = FactoryGirl(:user)
    

    instead of

      @user = Factory(:user)
    
    0 讨论(0)
  • 2021-02-14 08:47

    For me I had to add require 'factory_girl' to test_helper.rb

    0 讨论(0)
  • 2021-02-14 08:48

    As per the latest version of Factory Girl (currently v4.0.0) rewrite factories.rb

    FactoryGirl.define do 
      factory :user do
        name                  "Michael Hartl"
        email                 "mhartl@example.com"
        password              "foobar"
        password_confirmation "foobar"
      end
    end
    

    then call it from your users controller specs as:

    FactoryGirl.create(:user)
    
    0 讨论(0)
提交回复
热议问题