首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何用selenium测试rails邮件程序

如何用selenium测试rails邮件程序
EN

Stack Overflow用户
提问于 2014-08-12 18:48:12
回答 1查看 141关注 0票数 0

我试图编写一个selenium/capybara测试,点击生成电子邮件的按钮,然后验证电子邮件是否已经发送。我需要能够访问电子邮件的内容以及。

例如,当点击“忘记您的密码?”链接,然后提交表单,则发送电子邮件。我在服务器日志中看到了电子邮件:

代码语言:javascript
运行
复制
11:19:00 web.1    | [127.0.0.1] [60db47a6946763b2fe5ec5c34be2b8f3]   Rendered devise/mailer/reset_password_instructions.html.erb (1.7ms)
11:19:00 web.1    | [127.0.0.1] [60db47a6946763b2fe5ec5c34be2b8f3] 
11:19:00 web.1    | Sent mail to owner@MyApp.com (38.7ms)
11:19:00 web.1    | [127.0.0.1] [60db47a6946763b2fe5ec5c34be2b8f3] Date: Tue, 12 Aug 2014 11:19:00 -0700
11:19:00 web.1    | From: MyApp <messages@MyApp.com>
11:19:00 web.1    | Reply-To: MyApp <messages@MyApp.com>
11:19:00 web.1    | To: owner@MyApp.com
11:19:00 web.1    | Message-ID: <53ea5a9493c4f_827b3fc125033bdc91470@Gregs-MacBook-Air.local.mail>
11:19:00 web.1    | Subject: MyApp - Password Reset Instructions
11:19:00 web.1    | Mime-Version: 1.0
11:19:00 web.1    | Content-Type: text/html;
11:19:00 web.1    |  charset=UTF-8
11:19:00 web.1    | Content-Transfer-Encoding: 7bit
11:19:00 web.1    | X-MC-Track: opens
11:19:00 web.1    | X-MC-Tags: devise_reset_password_instructions
11:19:00 web.1    | 
11:19:00 web.1    | <p>Hello owner@MyApp.com!</p>
11:19:00 web.1    | 
11:19:00 web.1    | <p>Someone has requested a link to change your password. You can do this through the link below.</p>
11:19:00 web.1    | 
11:19:00 web.1    | <p><a href="http://192.168.11.44:3000/users/password/edit?reset_password_token=wh3rTHUH6KctsHxhxxqy">Change my password</a></p>
11:19:00 web.1    | 
11:19:00 web.1    | <p>If you didn't request this, please ignore this email.</p>
11:19:00 web.1    | <p>Your password won't change until you access the link above and create a new one.</p>

我如何从我的测试中访问这个?

app/mailers中,我有两个文件。

my_mailer.rb

代码语言:javascript
运行
复制
class MyMailer < Devise::Mailer
  def headers_for(action, opts)
    headers = {
        :subject       => subject_for(action),
        :to            => resource.email,
        :from          => mailer_sender(devise_mapping),
        :reply_to      => mailer_reply_to(devise_mapping),
        :template_path => "devise/mailer",
        :template_name => action,
        "X-MC-Track"   => "opens",
        "X-MC-Tags"    => "devise_#{action}"
    }.merge(opts)
  end
end

message.rb

代码语言:javascript
运行
复制
class Message < ActionMailer::Base
  require 'mandrill'
  default from: "MyApp <messages@MyApp.com>"

  def send_welcome_email(to_user)
    mandrill = Mandrill::API.new ENV['MANDRILL_API_KEY']
    template = mandrill.templates.render "welcome-to-MyApp", [], [
      {:name => 'username', :content => to_user.name},
      {:name => 'subject', :content => "Welcome to MyApp, #{to_user.name}"}
    ]
    @body = template['html']
    mail(:subject => "Welcome to MyApp, #{to_user.name}", :to => to_user.email, "tags" => ["In Trial - Welcome"],)
    headers['X-MC-Track'] = "opens"
    headers['X-MC-Tags'] ="invite_sent"
  end
end
EN

回答 1

Stack Overflow用户

发布于 2014-08-13 08:14:18

你没有。

只需写一个单独的邮件规范。

考试就像数学证明:

代码语言:javascript
运行
复制
Given user submits mail sending form, no error occurs and 'Mail was submitted' is displayed.
Given your Mailer is generating proper content.
Given Rails Mailers work
Given the Mail protocol works 
Then the mail will be delivered properly
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25271869

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档