I have a model Answer:
class Answer < ActiveRecord::Base
attr_accessible :content
belongs_to :question
end
In my Question model, i have defined has_many :answers. My Answer model have three column: content (text), question_id (integer), correct(boolean). Default value of correct column is false.
I created factories to create Answer object:
factory :answer do
content "Content of an answer"
question
factory :accept_answer do
correct true
end
end
In my rspec file, i created new answer object successfully with below code:
let(:answer) { FactoryGirl.create(:answer, question: question) }
subject { answer }
its(:correct) { should be_false }
But when i used below code to create 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
It has error
Failure/Error: let(:accept_answer) { FactoryGirl.create(:accept_answer, question: question) }
ArgumentError:
Factory not registered: accept_answer
I don’t know what wrong with my code 🙁
The problem because spork server can’t regonize what i changes, so i have restart spork server and it works.