I have the following Rspec test:
it "Password reset instructions" do
user = Factory(:user)
user.send_reset_password_instructions
email = last_email
email.body.encoded.should match(edit_user_password_url(:reset_password_token => user.reset_password_token))
end
Trying to match the edit_password_url in a mailer
!!!
%html
%head
%meta{:content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
%body
%h1 Hey #{@resource.first_name}
%p Forget your password? Its cool-- it happens to the best of us.
%p To reset the password to your TippingPress account, click the link below:
%p= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token)
%p If you didn’t request a password change, you can email us at support@tippingpress.com.
%p Best,
%p
Alex & Larson
%br
= link_to "TippingPress.com", "http://www.tippingpress.com"
I get the following error:
1) UserMailer Password reset instructions
Failure/Error: email.body.encoded.should match(edit_user_password_url(:reset_password_token => user.reset_password_token))
expected "<!DOCTYPE html>\r\n<html>\r\n<head>\r\n<meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>\r\n</head>\r\n<body>\r\n<h1>Hey Tester</h1>\r\n<p>Forget your password? Its cool-- it happens to the best of us.</p>\r\n<p>To reset the password to your TippingPress account, click the link below:</p>\r\n<p><a href=\"http://localhost:3000/users/password/edit?reset_password_token=8RMhiAxsRihME1mL7JiE\">Change my password</a></p>\r\n<p>If you didn’t request a password change, you can email us at support@tippingpress.com.</p>\r\n<p>Best,</p>\r\n<p>\r\nAlex & Larson\r\n<br>\r\n<a href=\"http://www.tippingpress.com\">TippingPress.com</a>\r\n</p>\r\n</body>\r\n</html>\r\n" to match "http://localhost:3000/users/password/edit?reset_password_token=8RMhiAxsRihME1mL7JiE"
Seems like the two urls match, I’m assuming this is some kind of error due to my lack of knowledge of REGEX or character encoding. Thank you in advance!
Indeed, you’re not passing a regexp to the
matchmethod, but a mere string.You’d better do: