Last Updated: February 25, 2016
·
723
· rongworks

Conflicting factories factory_girl & factory_girl_rails

While writing a redmine plugin I wanted to use FactoryGirl, so in my Gemfile I had gem 'factorygirlrails' and used factories in my tests. This gave me an

ArgumentError: factory not registered xxx

I discovered that the bundle already contained gem 'factory_girl'. So I had two factories, I could not delete any of the Gem specs (because my plugin needs FactoryGirl and other plugins can as well use FactoryGirl), so I had to resolve the conflict.
My factories were ignored, because FactoryGirl already had another load_path for factories.

In my test_helper.rb I defined

FactoryGirl.definition_file_paths << File.expand_path('../factories', __FILE__)
FactoryGirl.find_definitions

My factories are defined in test/factories.rb. So for other locations '../factories' has to be adjusted.
Problem solved.