如何使用黄瓜测试基于延迟作业的功能集成?
我想在黄瓜上测试一些需要延迟作业才能工作的功能。我已经定义了以下步骤:
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 "[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
应该收到 n 封电子邮件 步骤由 email_spec< 定义/a> 并定义为:
Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails?$/ do |address, amount|
unread_emails_for(address).size.should == parse_email_count(amount)
end
因此测试失败,告诉我我收到 0 封电子邮件([email protected] 在此测试中被真实电子邮件替换,我没有收到任何内容)。我怀疑工人并没有真正开始。我应该检查什么?顺便说一句,当我在开发模式下测试时,我确实收到了那封电子邮件。
谢谢
编辑:
看起来我收到了SQLite3::BusyException:
SQLite3::BusyException:数据库已锁定:插入“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 => "[email protected]",
:password => "mypassword",
:authentication => "plain",
:enable_starttls_auto => true
}
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
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' }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抱歉,但答案是放弃 sqlite。延迟的作业会锁定数据库,因此您的应用程序会停止运行。
Sorry, but the answer is to move off of sqlite. Delayed job locks the database so your app gets staved.