I'm using rspec/capybara/devise to conduct Integration testing in an app. One of the features of the app is the ever-populate "Account Registration" using a confirm feature (ie sign up - get an confirmation email - click on the link - account is validated).
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
Here are my helpers:
module MailerMacros
def last_email
ActionMailer::Base.deliveries.last
end
end
The confirmation link is in the HTML email generated. It would be lovely to be able to do something like this (assuming "Confirm My Account") is the link to the account validation.
last_email.body.find_link("Confirm My Account").click_link
Does anyone have any suggestions in being able to identify links in an email that could go into a request_spec?
Thanks