标签: email-spec

如何为邮件拦截器编写RSpec?

我正在使用邮件拦截器如下:

为setup_mail.rb

Mail.register_interceptor(MailInterceptor) if Rails.env != "production" 
Run Code Online (Sandbox Code Playgroud)

class MailInterceptor

class MailInterceptor  
  def self.delivering_email(message)  
    message.subject = "#{message.subject} [#{message.to}]"
    message.to = "xxxxx@xxxxxx.com"
  end
end
Run Code Online (Sandbox Code Playgroud)

我无法为这个拦截器创建一个rspec,因为rake规范不会发生这种情况.

我有以下规格:

  describe "MailInterceptor" do 
    it "should be intercepted" do
      @email = UserMailer.registration_automatically_generated(@user)
      @email.should deliver_to("xxxxx@xxxxxx.com")      
    end
  end
Run Code Online (Sandbox Code Playgroud)

在test.log中,我看到deliver_to不是拦截器.关于如何为拦截器编写rspec的任何想法?

谢谢

rspec ruby-on-rails ruby-on-rails-3 email-spec

16
推荐指数
1
解决办法
1285
查看次数

rspec-email - 如何获取正文?

我正在使用带有email-spec gem的rspec.我正在尝试:

last_delivery = ActionMailer::Base.deliveries.last
last_delivery.body.should include "This is the text of the email"
Run Code Online (Sandbox Code Playgroud)

但这不起作用,有没有办法说出身体,文字版本?内容类型:文字/文字?

谢谢

rspec rspec2 email-spec

15
推荐指数
5
解决办法
9009
查看次数

如何在mailgun中重新发送丢弃的电子邮件

如何在mailgun中重新发送丢弃的电子邮件?

我正在使用mailgun在我的应用程序中发送邮件,但有些邮件被删除了.有没有方法重新发送丢弃的邮件?

rest sendmail email-spec mailgun

6
推荐指数
3
解决办法
5226
查看次数

电子邮件规范与Rails中的正文内容不匹配

我正在使用email_spec gem来测试一个简单的电子邮件,但由于某种原因,正文内容似乎是空的:

  1) ContactMailer welcome email to new user renders the body
     Failure/Error: mail.should have_body_text("Hi")
       expected the body to contain "Hi" but was ""
     # ./spec/mailers/contact_mailer_spec.rb:17:in `block (3 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)

其他每个例子都过去了 调用模板文件welcome_email.text.erb.不确定为什么身体不匹配,但电子邮件在发送时确实有一个正文.

编辑:Rspec代码是:

let(:mail) { ContactMailer.welcome_email(email) }


it "renders the body" do
  mail.should have_body_text("Hi")
end
Run Code Online (Sandbox Code Playgroud)

email rspec ruby-on-rails email-spec

3
推荐指数
1
解决办法
1505
查看次数