【发布时间】:2011-10-03 19:00:44
【问题描述】:
我正在使用如下邮件拦截器:
setup_mail.rb
Mail.register_interceptor(MailInterceptor) if Rails.env != "production"
邮件拦截器类
class MailInterceptor
def self.delivering_email(message)
message.subject = "#{message.subject} [#{message.to}]"
message.to = "xxxxx@xxxxxx.com"
end
end
我无法为此拦截器创建 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
在 test.log 中,我看到 Deliver_to 不是拦截器。关于如何为拦截器编写 rspec 的任何想法?
谢谢
【问题讨论】:
-
拦截器在开发中工作吗? setup_mail.rb 存储在哪里?
-
是的,它是在 initalizers/setup_mail.rb w Mail.register_interceptor(MailInterceptor) if Rails.env != "production" 中设置的
标签: ruby-on-rails ruby-on-rails-3 rspec email-spec