如何测试 mailgun 用水豚发送邮件?
how to test mailgun sending emails with capybara?
我的应用程序在 rails 上,我向应用程序用户发送了一封电子邮件,目的不同——从设计通知到任何其他目的。我正在使用 mailgun 发送电子邮件,就像这样:
def send_simple_message
RestClient.post "https://api:YOUR_API_KEY"\
"@api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages",
:from => "Excited User <mailgun@YOUR_DOMAIN_NAME>",
:to => "bar@example.com, YOU@YOUR_DOMAIN_NAME",
:subject => "Hello",
:text => "Testing some Mailgun awesomness!"
end
收发邮件效果不错,但我想知道,如何使用 Capybara 在验收测试中对其进行测试。 Capybara-email 根本不起作用。有什么想法吗?
已更新
根据最佳答案,重建了我的发送方法以使用 mailgun gem。现在,我可以在 rspec 中收到电子邮件,因为我不知道如何单击电子邮件中的链接。我尽我所能但没有运气。将得到帮助。
capybara-email 可能不适合你,因为你没有使用 Rails ActionMailer 与 Mailgun 集成 - 除此之外,你可以使用 mailgun-ruby gem 在自述文件中记录了测试模式 - https://github.com/mailgun/mailgun-ruby/blob/master/README.md#testing-mail-deliveries。如果你不打算使用它,那么你需要使用 WebMock 或等价物来模拟请求
我的应用程序在 rails 上,我向应用程序用户发送了一封电子邮件,目的不同——从设计通知到任何其他目的。我正在使用 mailgun 发送电子邮件,就像这样:
def send_simple_message
RestClient.post "https://api:YOUR_API_KEY"\
"@api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages",
:from => "Excited User <mailgun@YOUR_DOMAIN_NAME>",
:to => "bar@example.com, YOU@YOUR_DOMAIN_NAME",
:subject => "Hello",
:text => "Testing some Mailgun awesomness!"
end
收发邮件效果不错,但我想知道,如何使用 Capybara 在验收测试中对其进行测试。 Capybara-email 根本不起作用。有什么想法吗?
已更新
根据最佳答案,重建了我的发送方法以使用 mailgun gem。现在,我可以在 rspec 中收到电子邮件,因为我不知道如何单击电子邮件中的链接。我尽我所能但没有运气。将得到帮助。
capybara-email 可能不适合你,因为你没有使用 Rails ActionMailer 与 Mailgun 集成 - 除此之外,你可以使用 mailgun-ruby gem 在自述文件中记录了测试模式 - https://github.com/mailgun/mailgun-ruby/blob/master/README.md#testing-mail-deliveries。如果你不打算使用它,那么你需要使用 WebMock 或等价物来模拟请求