1

I want to test some features that needs delayed jobs to work, on cucumber. I have defined the following step:

Given /^jobs are being dispatched$/ do 
    Delayed::Worker.new.work_off
end

Right now, I am trying to test email notifications. So I have the following scenario:

Scenario: Receiving email when signing up   
      Given I am on the signup page
      And I fill in "user[email]" with "test@test.com" 
      And I fill in "user[password]" with "password"
      And I fill in "user[password_confirmation]" with "password"
      And I press "Sign up"
      Then I should be on the homepage
      Given jobs are being dispatched
      Then "test@test.com" should receive 1 emails

The should receive n emails step is defined by email_spec and is defined as:

Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails?$/ do |address, amount|
  unread_emails_for(address).size.should == parse_email_count(amount)
end

So the test fails telling me that I am receiving 0 emails (the test@test.com is replaced by a real email in this test and I am not receiving anything). I suspect that the worker didn't really start. What should I check? By the way, when I test in development mode I really receive that email.

Thanks

Edit:

It looks like I am getting a SQLite3::BusyException:

SQLite3::BusyException: database is locked: INSERT INTO "delayed_jobs" ....

Now to investigate why and how I can get rid of that! Any idea? (besides moving my database to PostgreSQL or mySQL).

Edit: Ok, I moved to PostgreSQL from SQLite, the records are being inserted into Delayed::Job but the email tests fail.

The config/environments/test.rb file contains:

 config.action_mailer.delivery_method = :test
  config.action_mailer.perform_deliveries = true

  config.action_mailer.smtp_settings = {
     :address              => "smtp.gmail.com",
     :port                 => 587,
     :domain               => "mydomain.com",
     :user_name            => "name@mydomain.com",
     :password             => "mypassword",
     :authentication       => "plain",
     :enable_starttls_auto => true
   }

  config.action_mailer.default_url_options = { :host => 'localhost:3000' } 
Amokrane Chentir
  • 29,907
  • 37
  • 114
  • 158
  • What is config.action_mailer.delivery_method set to in config.rb? Is a record being inserted into the delayed_jobs table? – Andy Waite May 17 '11 at 20:16
  • @Andy - Looks like the record is not inserted because of the SQLite3::BusyException. – Amokrane Chentir May 18 '11 at 10:44
  • Ok the record are being inserted into the delayed_job table but the tests are still failling. I added the content of the config/environments/test.rb file. – Amokrane Chentir May 19 '11 at 13:47
  • @AmokraneChentir while this is old, I'm getting the same behavior with mysql, where jobs are in the db but they are not getting worked on. any ideas? – Nick Ginanto Jan 19 '17 at 05:50

1 Answers1

1

Sorry, but the answer is to move off of sqlite. Delayed job locks the database so your app gets staved.

oreoshake
  • 4,712
  • 1
  • 31
  • 38