2012-10-26 62 views
1

我有一個標準答案:爲什麼我會收到'工廠未註冊'錯誤?

class Answer < ActiveRecord::Base 
    attr_accessible :content 

    belongs_to :question 
end 

在我的問題的模型,我已經定義has_many :answers。我的答案模型有三列:內容(文本),question_id(整數),正確(布爾值)。 correct列的默認值爲false

我創建工廠創建應答對象:

factory :answer do 
    content "Content of an answer" 
    question 

    factory :accept_answer do 
    correct true 
    end 
end 

在我的RSpec的文件,我創造了新的答案對象成功下面的代碼:

let(:answer) { FactoryGirl.create(:answer, question: question) } 

subject { answer } 
its(:correct) { should be_false } 

但是當我用下面的代碼創建accept_answer object:

describe "an accepted answer" do 
    let(:accept_answer) { FactoryGirl.create(:accept_answer, question: question) } 
    it { accept_answer.correct.should be_true } 
end 

它有錯誤

Failure/Error: let(:accept_answer) { FactoryGirl.create(:accept_answer, question: question) } 
ArgumentError: 
    Factory not registered: accept_answer 

我不知道有什麼錯我的代碼:(

+0

您使用的是什麼版本的FactoryGirl? –

+0

它的版本是4.1.0。 – Thanh

回答

3

的問題,因爲叉勺服務器無法regonize我的變化,所以我必須重新啓動服務器叉勺和它的作品。

相關問題