Skip to content

Instantly share code, notes, and snippets.

@bobisme
Created November 1, 2017 22:16
Show Gist options
  • Save bobisme/d8681434af28f170a607a0c3d1398dce to your computer and use it in GitHub Desktop.
Save bobisme/d8681434af28f170a607a0c3d1398dce to your computer and use it in GitHub Desktop.

Database Cleaner:

group :test do ...
  gem "database_cleaner"
  ...
end

Support

# spec/support/factory_girl.rb
RSpec.configure do |config|
  config.include FactoryGirl::Syntax::Methods
  config.before(:suite) do
    begin
      DatabaseCleaner.start
      # lint all the factories
      FactoryGirl.lint
    ensure
      DatabaseCleaner.clean 
    end
  end
end
# This should be in rails_helper
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
# spec/factories.rb:
FactoryGirl.define do
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment