Last active
August 29, 2015 14:19
-
-
Save juno/641c9c004db834923da9 to your computer and use it in GitHub Desktop.
RSpec with ActiveJob
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
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 |
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
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