All you have to do is require 'rspec_factory_girl' and then the definitions.
Usually, if you put it in spec_helper.rb , this will require all the files in the spec/ directory, which means that if you have your factories defined, for example, in spec/factories.rb , they will automatically load.
However, you need to add require 'spec_helper' at the top of your spec file, which you don't seem to be doing.
If you do not want to use the spec_helper.rb file spec_helper.rb this way, simply do a manual definition, for example require 'factories' .
One little trick if you use something like spork and you need to restart your factories manually before each run
FactoryGirl.factories.clear
edit: full spork example
Spork.each_run do require 'factory_girl_rails' # reload all the models Dir["#{Rails.root}/app/models/**/*.rb"].each do |model| load model end # reload all factories FactoryGirl.factories.clear Dir.glob("#{::Rails.root}/spec/factories/*.rb").each do |file| load "#{file}" end # reload routes YourAppName::Application.reload_routes! end
Jakub arnold
source share