Skip to content

Instantly share code, notes, and snippets.

@pascalesdedy
Last active October 20, 2018 15:13
Show Gist options
  • Save pascalesdedy/955e91b4f0a0b619ff7f728318111ccd to your computer and use it in GitHub Desktop.
Save pascalesdedy/955e91b4f0a0b619ff7f728318111ccd to your computer and use it in GitHub Desktop.
spec/rails_helper.rb used in Simple CRUD TDD
# require database cleaner at the top level
require 'database_cleaner'
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end
RSpec.configure do |config|
# [...]
# add `FactoryBot` methods
config.include FactoryBot::Syntax::Methods
# start by truncating all the tables but then use the faster transaction strategy the rest of the time.
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
DatabaseCleaner.strategy = :transaction
end
# start the transaction strategy as examples are run
config.around(:each) do |example|
DatabaseCleaner.cleaning do
example.run
end
end
# [...]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment