在測驗我的郵件內容時,在實際郵件中它顯示郵件內容,但是在 rspec 中測驗我的郵件時它不顯示內容,因為它只顯示電子郵件影像附件,以前沒有在郵件中發送附件,它顯示郵件正文在rspec中,但是現在附上圖片附件后不顯示rspec中的內容,那么如何獲取內容
我的 rspec 結果
#<Mail::Body:0x00555c3bbcef70
@boundary="--==_mimepart_61bb2dce1d6b1_f92aae1ba4534536817",
@charset="US-ASCII",
@encoding="7bit",
@epilogue=nil,
@part_sort_order=["text/plain", "text/enriched", "text/html"],
@parts=
[#<Mail::Part:46927317154560, Multipart: false, Headers: <Content-Type: text/html>>,
#<Mail::Part:46927293531360, Multipart: false, Headers: <Content-Type: image/jpeg; filename="image.jpg">, <Content-Transfer-Encoding: binary>, <Content-Disposition: attachment; filename="image.jpg">, <Content-ID: <61bb2dc84fb25_f92486@c430e0bef0fd.mail>>>,
#<Mail::Part:46927312188120, Multipart: false, Headers: <Content-Type: image/png; filename="user2_app.png">, <Content-Transfer-Encoding: binary>, <Content-Disposition: attachment; filename="user2_app.png">, <Content-ID: <61bb2dca13d5f_565ac@c430e0bef0fd.mail>>>,
#<Mail::Part:469273513434, Multipart: false, Headers: <Content-Type: image/png; filename="user2_app.png">, <Content-Transfer-Encoding: binary>, <Content-Disposition: attachment; filename="user2.png">, <Content-ID: <61bb2dcc44fa_34346bd@c430e0bef0fd.mail>>>,
,
@preamble=nil,
@raw_source="">
我的 rspec 方法
mail = Mailer.send_mail_to_user(user_name,address)
expect(mail.body).to include("Welcome user")
但在我發送的實際郵件中包含文本歡迎用戶
但在 rspec 中它沒有顯示?
如何測驗,請幫助我
uj5u.com熱心網友回復:
expect(mail.body).to include("Welcome user")僅當您發送僅包含文本的簡單電子郵件時才真正起作用。當您發送多部分電子郵件時,您需要匹配電子郵件的特定部分:
let(:html_body) do
mail.body.parts.find { |p| p.content_type.match 'text/html' }.body.raw_source
end
it "contains hello world" do
expect(html_body).to include("Welcome user")
end
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/383297.html
標籤:红宝石轨道 PostgreSQL的 规格 红宝石
