I'm trying to get used to writing specifications, but this is becoming increasingly frustrating.
Suppose I have two simple models: Userand Story. Each model uses a relationship belongs_to. Each model also uses validates :foo_id, presence: true.
However, FactoryGirl creates a few entries.
FactoryGirl.define do
factory :user do
email "foo@bar.com"
password "foobarfoobar"
end
factory :story do
title "this is the title"
body "this is the body"
user
end
end
This simple test fails:
require 'rails_helper'
describe Story do
let(:user) { FactoryGirl.create(:user) }
let(:story) { FactoryGirl.create(:story) }
it 'should belong to User' do
story.user = user
expect(story.user).to eq(user)
end
end
What am I missing here? I cannot build a Storyfactory without User, but I need this to be only one entry User.
source
share