Skip to content

Instantly share code, notes, and snippets.

Last active June 21, 2018 07:20
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Spree test environment setting with rspec, factory_girl_rails and spring


  • rspec-rails (3.3.3)
  • factory_girl_rails (4.5.0)
  • spring (1.4.0)
  • spring-commands-rspec (1.0.4)


  • spring rspec generates errors with spree-generated-factories when it is used the way like require 'spree/testing_support/factories')


  • There is already a solution by @derekprior (spree/spree#6534)
  • Use load instead of require
require 'spec_helper'
require 'rspec/rails'
require 'ffaker' # important. spree-generated-factories require this.
load 'spree/testing_support/factories.rb'
Copy link

If you find yourself with factories not defined error when using this technique with Spring, try to require factory_girl inside rails_helper.rb file.

# in Gemfile
gem 'factory_girl_rails', require: false

# in rails_helper.rb
require 'factory_girl_rails'


Copy link

@sunkibaek 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment