我使用的RSpec /豚/設計中的應用進行集成測試。該應用程序的功能之一是使用確認功能(即註冊 - 獲取確認電子郵件 - 點擊鏈接 - 帳戶經過驗證)的不斷填充的「帳戶註冊」。測試「賬戶確認書」與軌/ rspec的/豚/設計
require 'spec_helper'
describe "User Authentication" do
describe "New user" do
before(:each) do
@user = Factory.build(:user)
end
it "can confirm account by clicking on confirmation link" do
visit root_path
click_link "Register"
page.should have_content "Register for an account"
fill_in "user_email", :with => @user.email
fill_in "user_password", :with => @user.password
fill_in "user_password_confirmation", :with => @user.password
fill_in "user_first_name", :with => @user.first_name
fill_in "user_last_name", :with => @user.last_name
fill_in "user_city", :with => @user.city
fill_in "user_province", :with => @user.province
fill_in "user_country", :with => @user.country
fill_in "user_expertise", :with => @user.expertise
choose "user_experience_professional"
click_button "Go!"
last_email.to.should include(@user.email)
end
end
end
這裏是我的助手:
module MailerMacros
def last_email
ActionMailer::Base.deliveries.last
end
end
的確認鏈接是生成的HTML電子郵件。能夠做到這樣的事情(假設「確認我的賬戶」)是賬戶驗證的鏈接將是可愛的。
last_email.body.find_link("Confirm My Account").click_link
有沒有人有任何建議可以識別電子郵件中的鏈接可以進入request_spec?
感謝
剛剛意識到這是一個歲的問題。 – PriyankaK 2013-11-06 16:51:08
仍幫我。把我放到email_spec寶石上,這真是太棒了!您也可以使用email_spec中的'click_first_link_in_email電子郵件' – mattvv 2014-03-16 00:54:08
@mattvv我嘗試過'''click_first_link_in_email''',但沒有爲我工作。感謝您的回覆! – PriyankaK 2014-03-18 19:11:04