Skip to content

Commit

Permalink
Merge pull request #1489 from morgoth/have_enqueued_job-descriptive-e…
Browse files Browse the repository at this point in the history
…rror

Throw descriptive error when have_enqueued_job matcher is used with non test adapter
  • Loading branch information
JonRowe committed Nov 13, 2015
2 parents 947e7ed + e327b00 commit f0005ec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/rspec/rails/matchers/active_job.rb
Expand Up @@ -158,6 +158,9 @@ def queue_adapter
# HelloJob.set(wait_until: Date.tomorrow.noon, queue: "low").perform_later(42)
# }.to have_enqueued_job.with(42).on_queue("low").at(Date.tomorrow.noon)
def have_enqueued_job(job = nil)
unless ::ActiveJob::QueueAdapters::TestAdapter === ::ActiveJob::Base.queue_adapter
raise StandardError, "To use have_enqueued_job matcher set `ActiveJob::Base.queue_adapter = :test`"
end
ActiveJob::HaveEnqueuedJob.new(job)
end
end
Expand Down
11 changes: 11 additions & 0 deletions spec/rspec/rails/matchers/active_job_spec.rb
Expand Up @@ -207,5 +207,16 @@ def to_global_id(options = {})
}.to have_enqueued_job(hello_job).with(42).on_queue("low").at(date).exactly(2).times
}.to raise_error(message)
end

it "throws descriptive error when no test adapter set" do
queue_adapter = ActiveJob::Base.queue_adapter
ActiveJob::Base.queue_adapter = :inline

expect {
expect { heavy_lifting_job.perform_later }.to have_enqueued_job
}.to raise_error("To use have_enqueued_job matcher set `ActiveJob::Base.queue_adapter = :test`")

ActiveJob::Base.queue_adapter = queue_adapter
end
end
end

0 comments on commit f0005ec

Please sign in to comment.