email-spec gem で rspec を使用しています。私はやろうとしています:
last_delivery = ActionMailer::Base.deliveries.last
last_delivery.body.should include "This is the text of the email"
しかし、それは機能しません。本文、テキスト バージョンと言う方法はありますか? コンテンツ タイプ: テキスト/テキスト?
ありがとう
email-spec gem で rspec を使用しています。私はやろうとしています:
last_delivery = ActionMailer::Base.deliveries.last
last_delivery.body.should include "This is the text of the email"
しかし、それは機能しません。本文、テキスト バージョンと言う方法はありますか? コンテンツ タイプ: テキスト/テキスト?
ありがとう
Body は実際にはMail::Bodyインスタンスです。その上で raw_source を呼び出すと、うまくいくはずです。
last_delivery = ActionMailer::Base.deliveries.last
last_delivery.body.raw_source.should include "This is the text of the email"
上記のすべてのオプションを試してうまくいかなかった後 (Rails 3.2.13)、Ruby ガイド(セクション 6 は TestUnit でのテストに関するもの) でいくつかの情報を見つけ、必要に応じて正確に動作するようにしました。
last_delivery = ActionMailer::Base.deliveries.last
last_delivery.encoded.should include("This is the text of the email")
それが役立つことを願っています!
あなたはそれを呼び出すことができます#to_s
。
last_delivery.to_s.should include "This is the text of the email"
マルチパートメールの場合:
last_delivery.first.to_s.should include "This is the text of the email"
テスト済みで、Rails 4 で動作していることがわかった
Rails 4 では、デフォルトでlast_delivery.body.should include "This is the text of the email"
問題なく動作します。
expect(last_delivery).to have_body_text(/This is the text of the email/)