我想在黄瓜上测试一些需要延迟工作才能工作的功能。我已经定义了以下步骤:
Given /^jobs are being dispatched$/ do
Delayed::Worker.new.work_off
end
现在,我正在尝试测试电子邮件通知。所以我有以下场景:
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
should receive n emails步骤由email_spec定义,定义为:
Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails?$/ do |address, amount|
unread_emails_for(address).size.should == parse_email_count(amount)
end
所以测试失败告诉我我收到了 0 封电子邮件(test@test.com 在这个测试中被真实的电子邮件取代,我没有收到任何东西)。我怀疑工人并没有真正开始。我应该检查什么?顺便说一句,当我在开发模式下测试时,我真的收到了那封电子邮件。
谢谢
编辑:
看起来我得到了一个SQLite3::BusyException:
SQLite3::BusyException: 数据库被锁定: INSERT INTO "delayed_jobs" ....
现在来调查为什么以及如何摆脱它!任何的想法?(除了将我的数据库移动到 PostgreSQL 或 mySQL 之外)。
编辑:
好的,我从 SQLite 迁移到 PostgreSQL,正在插入记录,Delayed::Job
但电子邮件测试失败。
config/environments/test.rb 文件包含:
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' }