2013-10-25 73 views
1

我有功能規格測試:Rspec的:click_link在電子郵件正文

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

回答

3

你可以嘗試這樣的事情:

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

謝謝,我添加鏈接標題模式及其作品如預期而已。 – ole