Last active
October 13, 2023 14:44
-
-
Save kazu69/ad229ae15cc1857280bb to your computer and use it in GitHub Desktop.
Such as setting when you write a test of parallel processing in ActiveRecord
This file contains 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
# spec_helper.rb | |
RSpec.configure do |config| | |
... | |
# テスト完了後一度だけ実行される | |
config.after(:suite) do | |
DatabaseCleaner.clean_with(:truncation) | |
end | |
# 各テスト実行前に実行される | |
config.before(:each) do |spec| | |
# multithread が trueのときは truncation | |
if spec.metadata[:multithread] | |
DatabaseCleaner.strategy = :truncation | |
else | |
DatabaseCleaner.strategy = :transaction | |
end | |
DatabaseCleaner.start | |
end | |
# 各テスト実行後に実行される | |
config.after(:each) do | |
DatabaseCleaner.clean | |
end | |
... | |
end |
This file contains 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 'spec_helper' | |
describe Application do | |
# マルチスレッドのテスト | |
it 'multi thread doing', multithread: true do | |
... | |
end | |
end | |
This file contains 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
# spec_helper.rb | |
RSpec.configure do |config| | |
... | |
config.use_transactional_fixtures = false | |
... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment