私はモデルの答えを持っています:
class Answer < ActiveRecord::Base
attr_accessible :content
belongs_to :question
end
私の質問モデルでは、私は定義しhas_many :answers
ました。私の回答モデルには、コンテンツ (テキスト)、質問 ID (整数)、正しい (ブール値) の 3 つの列があります。correct
列のデフォルト値は ですfalse
。
Answer オブジェクトを作成するためのファクトリを作成しました。
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オブジェクトを作成したとき:
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
私のコードのどこが悪いのかわかりません:(