Last active
October 20, 2018 15:13
-
-
Save pascalesdedy/955e91b4f0a0b619ff7f728318111ccd to your computer and use it in GitHub Desktop.
spec/rails_helper.rb used in Simple CRUD TDD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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