Reputation: 1415
Hello i have a very simple Rspec test.
It was working until i used Factory Girl. I have tried so many ways to get it to pass.
I have been trying to get it pass for like 90 minutes its such a simple test.
Anyone know?
Here is error
1) Size is invalid without a title
Failure/Error: let(:size02) { FactoryGirl.create :size02 }
ActiveRecord::RecordInvalid:
Validation failed: Title can't be blank
This is the test
require 'rails_helper'
RSpec.describe Size, type: :model do
let(:size01) { FactoryGirl.create :size01 }
let(:size02) { FactoryGirl.create :size02 }
let(:size03) { FactoryGirl.create :size03 }
it "should have a matching title" do
expect(size01.title).to eq("XXLarge")
end
it "is invalid without a title" do
expect(size02).to be_invalid
end
end
Factory Girl
FactoryGirl.define do
factory :size01, :class => Size do
title "XXLarge"
end
factory :size02, :class => Size do
title ""
end
factory :size03, :class => Size do
title "XXLarge"
end
end
Upvotes: 1
Views: 180
Reputation: 5241
Factory Girl cannot create the instance size02
, because it has no title and is therefore invalid. Try build
instead of create
, if you don't need persistence in your test:
let(:size02) { FactoryGirl.build :size02 }
Upvotes: 1