I'm trying to use Factory Girl for RSpec with Spork. Whenever I run my tests without spork, everything passes, but when I run it with Spork, all the tests that try to create an instance of a factory that depends on another factory, fail. For example:
3) Invitation has a correctly formed body
Failure/Error: request = FactoryGirl.create(:request, ....)
NoMethodError:
undefined method `user=' for #<Request:0x007f86b6a87890>
And my factories.rb
code looks roughly like this
FactoryGirl.define do
factory :user do
sequence(:first_name) { |n| "first_name#{n}" }
sequence(:last_name) { |n| "last_name#{n}" }
end
factory :request do
association :user, :factory => :user, :is_walker => false
end
end
My code only seems to break when there is an association, and then it tries to call the setter on the :user
. Why might this be happening?
Here are the versions I'm using
gem 'rails', '3.0.7'
gem 'rspec-rails', '2.6.1'
gem 'spork', '0.9.0.rc5'
gem 'factory_girl_rails', '1.0'
Do you have require 'factory_girl_rails
in your Spork.each_run
block?
I have use the following in my gemfile:
gem "factory_girl_rails", :require => false
in spec_helper.rb:
Spork.each_run do
require 'factory_girl_rails'
FactoryGirl.factories.clear
FactoryGirl.reload
end
Not sure if it will help but it's worth a shot.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With