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 "[email protected]"
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 "[email protected]" 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 [email protected] 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 => "[email protected]",
:password => "mypassword",
:authentication => "plain",
:enable_starttls_auto => true
}
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
Sorry, but the answer is to move off of sqlite. Delayed job locks the database so your app gets staved.