Factory Association of Girls with Spark Mismatch

I am 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 tests that try to create a Factory instance that depends on another factory fail. For instance:

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 something 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 broken when there is a connection, and then it tries to call setter on :user . Why can this happen?

Here are the versions I use

 gem 'rails', '3.0.7' gem 'rspec-rails', '2.6.1' gem 'spork', '0.9.0.rc5' gem 'factory_girl_rails', '1.0' 
+6
source share
2 answers

Do you have require 'factory_girl_rails in a Spork.each_run block?

I 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 this will help, but it's worth it.

+6
source

Are these any tests that have an association or any tests that try to create a query: factory? I never used spork, but the fact that it works without it makes me wonder if spork / factory_girl are fighting over "Request" ... worth a look.

0
source

Source: https://habr.com/ru/post/894518/


All Articles