2

I am using the devise-async gem to send my devise emails asynchronously - using Resque.

I am doing some simple RSpec controller tests to make sure the, say, forgotten password is being sent, by inspecting the ActionMailer::Base.deliveries array.

This used to work before I started using the devise-async gem. How can I "send" the emails on the queue immediately, so that they end up in ActionMailer::Base.deliveries?

For example - when I used delayed_job to send them asynchronously (not using the devise-async gem), I could add this to my devise initializer:

Delayed::Worker.delay_jobs = !Rails.env.test?

Which would deliver emails straight away to make it easier to test. So - is there a similar technique I can use when using devise-async?

2 Answers 2

3

I put the following line in spec_helper.rb:

Devise::Async.enabled = false

and it worked.

1
  • Great. This fixed my my service's spec examples asserting ActionMailer::Base.deliveries.count increase when a new confirmable user is created in the DB. The specs were passing before I introduced Devise-Async but afterwards those started failing.This config restored the failing spec examples. Sep 6, 2016 at 13:57
0

Ok - I have found the answer:

In an initializer file, do the following:

Resque::Mailer.excluded_environments = [:test]

For general Resque jobs, add the following:

Resque.inline = Rails.env.test?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.