Joerg
Joerg

Reputation: 3813

Using devise-async gem with RSpec

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?

Upvotes: 2

Views: 504

Answers (2)

Rolands Bondars
Rolands Bondars

Reputation: 3207

I put the following line in spec_helper.rb:

Devise::Async.enabled = false

and it worked.

Upvotes: 3

Joerg
Joerg

Reputation: 3813

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?

Upvotes: 0

Related Questions