Ruby 如何访问使用信函开启器gem打开的电子邮件中的链接
我正在使用Cucumber和Capybara进行一些QA自动化工作,并有一个步骤:Ruby 如何访问使用信函开启器gem打开的电子邮件中的链接,ruby,cucumber,capybara,Ruby,Cucumber,Capybara,我正在使用Cucumber和Capybara进行一些QA自动化工作,并有一个步骤: When(/^I follow the reset password link in the email$/) do last_email = ActionMailer::Base.deliveries.last password_reset_url = last_email.body.match(/http.*\/users\/password\/edit.*$/) visit password_r
When(/^I follow the reset password link in the email$/) do
last_email = ActionMailer::Base.deliveries.last
password_reset_url = last_email.body.match(/http.*\/users\/password\/edit.*$/)
visit password_reset_url
end
该步骤失败,原因是:
undefined method `body' for nil:NilClass (NoMethodError)
此外,在第一行之后删除binding.pry会导致last\u email
的结果为零,这很奇怪
有人对为什么会发生这种情况有什么建议或想法吗?如果您使用的是letter\u opener,那么电子邮件不会发送到ActionMailer,而是在不受Capybara控制的浏览器中打开。如果你想在水豚岛上处理电子邮件,你可能应该看看水豚岛的电子邮件宝石,而不是开封器。Letter_opener更多的是针对开发环境,而不是测试。在内容上是绝对正确的,并为您指明了未来的方向 下面是一个可能的示例,说明如何更改代码示例,假设您有另一个Cucumber步骤,该步骤已单击按钮/链接以发送重置密码说明:
When(/^I follow the reset password link in the email (.*)$/) do |email|
# finds the last email sent to the passed in email address.
# This also sets the `current_email` object, which you can think
# of as similar to Capybara's `page` object, but for an email.
open_email(email)
# Assuming the email link to change your password is called
# 'Change my password', you can just click it, just as you would
# on a Capybara `page`.
current_email.click_link 'Change my password'
end
点击链接后,您将进入任何
页面
,在那里您可以继续填写“新密码”,并使用“foobar”
等,我假设您已经在另一个步骤中进行了介绍。您找到解决方案了吗?