簡體   English   中英

RSpec梅勒測試匹配失敗

[英]RSpec Mailer test Match failing

我有以下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 support@tippingpress.com.
    %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 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"

似乎兩個網址匹配,我假設這是由於我缺乏REGEX或字符編碼的知識而導致的某種錯誤。 先感謝您!

實際上,你沒有將正則表達式傳遞給match方法,而只是一個字符串。

你最好這樣做:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM