Rspec:电子邮件正文中的click_link

时间:2013-10-25 07:06:39

标签: ruby rspec

我有功能规格测试:

describe "Reset password" do
  let(:last_email) { ActionMailer::Base.deliveries.last }

  it "should be success" do
    # ...
    page.should have_content t("users.passwords.sent")
    last_email.to.first.should eq user.email
    last_email.body.should have_content t("mail.body.recovery_instructions")

    # Here is click_link

    page.should have_content t("passwords.updated")
  end
end

如何点击位于last_email.body的链接?

1 个答案:

答案 0 :(得分:3)

您可以尝试这样的事情:

link = last_email.body.raw_source.match(/href="(?<url>.+?)">/)[:url]
visit link