Skip to content

Instantly share code, notes, and snippets.

@kazu69
Last active October 13, 2023 14:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazu69/ad229ae15cc1857280bb to your computer and use it in GitHub Desktop.
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
# 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
require 'spec_helper'
describe Application do
# マルチスレッドのテスト
it 'multi thread doing', multithread: true do
...
end
end
# 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