2012-02-10 55 views
2

我有以下Rspec的测试:RSpec的梅勒测试赛未能

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 

试图将edit_password_url在邮件

!!! 
%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 [email protected] 
    %p Best, 
    %p 
     Alex & Larson 
     %br 
     = link_to "TippingPress.com", "http://www.tippingpress.com" 

我碰到下面的错误匹配:

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 [email protected]</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" 

似乎这两个url匹配,我认为这是由于我缺乏REGEX或角色知识而导致的某种错误编码。先谢谢你!

回答

9

的确,您没有将正则表达式传递给match方法,而只是一个字符串。

你最好这样做:

email.body.encoded.should include(edit_user_password_url(:reset_password_token => user.reset_password_token))