railstutorial.org - undefined method `Factory'

前端 未结 10 1423
时光取名叫无心
时光取名叫无心 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: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)
    

提交回复
热议问题