代码之家  ›  专栏  ›  技术社区  ›  Ramon Tayag

Cucumber+EmailSpec+Rails3:为什么它说在实际工作时不发送电子邮件?

  •  3
  • Ramon Tayag  · 技术社区  · 15 年前

    我在用 EmailSpec 用黄瓜测试邮件。我的测试失败了,说没有发送电子邮件,但是 我找不到我的代码有任何问题,所以我在生产中尝试过,并发送电子邮件 .

    下面是失败的一步:

    # ...
    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 (ramon@email.com) 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
    

    我该怎么做才能修好这个测试?

    谢谢!

    1 回复  |  直到 15 年前
        1
  •  1
  •   Ramon Tayag    15 年前

    看来我 wasn't the only one 有这个问题!您应该将email_steps.rb中的默认电子邮件设置更改为希望接收电子邮件的电子邮件。