如何使用黄瓜测试基于延迟作业的功能集成?

发布于 2024-11-07 23:41:42 字数 2470 浏览 0 评论 0原文

我想在黄瓜上测试一些需要延迟作业才能工作的功能。我已经定义了以下步骤:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

趴在窗边数星星i 2024-11-14 23:41:43

抱歉,但答案是放弃 sqlite。延迟的作业会锁定数据库,因此您的应用程序会停止运行。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文