黄瓜 +电子邮件规范 + Rails3:为什么它实际上工作时说没有发送电子邮件?

发布于 2024-10-04 02:39:14 字数 1394 浏览 0 评论 0原文

我正在使用 EmailSpec 来测试 Cucumber 的电子邮件。我的测试失败,并表示没有发送电子邮件,但是我找不到我的代码有任何问题,因此我在生产中进行了尝试,并且发送了电子邮件

这是失败的步骤:

# ...
And I should see "You have requested for a condition report, and will be emailed one as soon as we are able to process your request." # features/step_definitions/web_steps.rb:107
And I should receive an email # features/step_definitions/email_steps.rb:51
  expected: 1,
       got: 0 (using ==) (RSpec::Expectations::ExpectationNotMetError)
  ./features/step_definitions/email_steps.rb:52:in `/^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails?$/'
  features/request_for_condition_reports.feature:18:in `And I should receive an email'
When I open the email                                                                                                                 # features/step_definitions/email_steps.rb:72
Then I should see "Ramon ([email protected]) wants a condition report for" in the email body 

这是发送电子邮件的类:

class ReportRequest < ActiveRecord::Base
  ...

  private

  def notify_admin
    Mailer.condition_report_request_to_admin(self).deliver
  end
end

我应该做什么来修复此测试?

谢谢!

I'm using EmailSpec to test emails with Cucumber. My tests fail and says no email is being sent, but I couldn't find anything wrong with my code, so I tried it in production and emails are sent.

Here's the failing step:

# ...
And I should see "You have requested for a condition report, and will be emailed one as soon as we are able to process your request." # features/step_definitions/web_steps.rb:107
And I should receive an email # features/step_definitions/email_steps.rb:51
  expected: 1,
       got: 0 (using ==) (RSpec::Expectations::ExpectationNotMetError)
  ./features/step_definitions/email_steps.rb:52:in `/^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails?$/'
  features/request_for_condition_reports.feature:18:in `And I should receive an email'
When I open the email                                                                                                                 # features/step_definitions/email_steps.rb:72
Then I should see "Ramon ([email protected]) wants a condition report for" in the email body 

And here's the class that sends the email:

class ReportRequest < ActiveRecord::Base
  ...

  private

  def notify_admin
    Mailer.condition_report_request_to_admin(self).deliver
  end
end

What should I do to fix this test?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

与君绝 2024-10-11 02:39:14

看来我不是唯一一个遇到这个问题的人!您应该将 email_steps.rb 中设置的默认电子邮件更改为您希望用来接收电子邮件的电子邮件。

It seems I wasn't the only one that had this problem! You're supposed to change the default email set in email_steps.rb to the email that you expect to receive emails with.

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