1

私はモデルの答えを持っています:

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

私のコードのどこが悪いのかわかりません:(

4

1 に答える 1

3

sporkサーバーが変更内容を認識できないため、問題が発生したため、sporkサーバーを再起動すると機能します。

于 2012-11-06T10:07:21.743 に答える