LoginSignup
6
2

More than 5 years have passed since last update.

テスト環境で非同期処理を同期処理にしたい場合のActiveJobの設定

Last updated at Posted at 2018-10-26

ジョブのテストを実行する際、ジョブの結果もテストしたい場合、下記のようなコードにできる。

if Rails.env.test?
  HogeJob.perform_now(params)
else
  HogeJob.perform_later(params)
end

全てのコードで条件分岐させるのは、冗長である。
下記のように、設定することで環境ごとに同期処理にすることができる。

config/environments/test.rb

Rails.application.config.active_job.queue_adapter = :inline

参考

RSpec でキューイングした ActiveJob を同期実行する - Qiita

6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2