Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

testing emails with capybara and delayed_job

inspired by the episode of railscast (http://railscasts.com/episodes/275-how-i-test) i tried to add some request specs to my app.

using delayed_job for sending my emails, i did not found an easy way to test the sending of emails within my capybara test. i tried:

    it "emails user when requesting password reset" do
      ...(some user action that triggers sending an email)...
      Delayed::Worker.new.work_off
      ActionMailer::Base.deliveries.last.to.should include(user.email)
    end

thanks for any hints or help!

like image 448
fluxsaas Avatar asked Dec 21 '22 09:12

fluxsaas


1 Answers

Much easier solution: Just create an initializer in config/initializers, e.g. delayed_job_config.rb

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

In your actual test you do not even need to know that delayed_job is deployed to send the mails, which keeps them clean and simple.

like image 115
emrass Avatar answered Jan 11 '23 10:01

emrass