Skip to content

Instantly share code, notes, and snippets.

@juno
Last active August 29, 2015 14:19
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 juno/641c9c004db834923da9 to your computer and use it in GitHub Desktop.
Save juno/641c9c004db834923da9 to your computer and use it in GitHub Desktop.
RSpec with ActiveJob
describe Foo do
describe '.process', active_job: true do
it 'キューにジョブを2件保存する' do
expect {
described_class.process
}.to change{ActiveJob::Base.queue_adapter.enqueued_jobs.size}.by(2)
end
end
end
RSpec.configure do |config|
# メタデータ active_job: true が設定されたテストの実行前後で
# ActiveJobのテスト用前処理を行う
# https://github.com/rails/rails/blob/master/activejob/lib/active_job/test_helper.rb
config.before(:all, active_job: true) do
@old_queue_adapter = ActiveJob::Base.queue_adapter
ActiveJob::Base.queue_adapter = :test
queue_adapter = ActiveJob::Base.queue_adapter
queue_adapter.enqueued_jobs.clear
queue_adapter.performed_jobs.clear
end
config.after(:all, active_job: true) do
ActiveJob::Base.queue_adapter = @old_queue_adapter
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment