Skip to content

Instantly share code, notes, and snippets.

@alvinsng
Created May 2, 2018 23:12
Show Gist options
  • Select an option

  • Save alvinsng/814a20f3be73a5c97060a082fb8c6948 to your computer and use it in GitHub Desktop.

Select an option

Save alvinsng/814a20f3be73a5c97060a082fb8c6948 to your computer and use it in GitHub Desktop.
# in config/environment.rb
if ENV['SPRING_ENV'] == 'test' && ENV['RAILS_ENV'] == 'test'
require File.expand_path('../../spec/spec_helper', __FILE__)
end
# in spec_helper.rb
# runs in Spring parent
unless MySpecHelper.factory_sequences
DatabaseCleaner.clean_with(:truncation)
RESEED_DB.call
MySpecHelper.factory_sequences = FactoryGirl.sequences
end
config.around(:each) do |example|
# runs in Spring fork
FactoryGirl.configuration.instance_variable_set(
:@sequences,
MySpecHelper.factory_sequences
)
DatabaseCleaner.cleaning do
example.run
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment