namespaced_engine
namespaced_engine copied to clipboard
Share factoriers across modules
Hi I have a suggestion, maybe you want to add it.
I had the case that I wanted to reuse factories of the core in other modules (and module factories in other modules) using rspec and factory_girl.
I solved it like this:
1 . In you module.gemspec
file add the spec/factories folder:
s.files = Dir["{app,config,db,lib}/**/*", "spec/factories/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
2 . In your lib/namespace/module_name/engine.rb
add the following initializer
initializer 'model_core.factories', after: 'factory_girl.set_factory_paths' do
FactoryGirl.definition_file_paths << File.expand_path('../../../../spec/factories', __FILE__) if defined?(FactoryGirl)
end
See: http://stackoverflow.com/questions/20261585/how-to-use-factorygirl-factories-from-an-engine