読み進めると、unit tests および functional tests で Mailer をテストすると説明してあります。 unit tests: 単体でテストを行い、入力値と出力値を比較して確認する。上記の 1, 2 の項目をテスト。 functional tests: Mailer を使うコントローラーやモデルが Mailer を正しく操作しているかテストする。正しいEメールが正しい時間に送られたかをテストする。上記 3 の項目をテスト。 Unit Testing ActionMailer::Base.deliveries に送信済みのメール(メールのオブジェクト)が配列で格納されます。 Action Mailer Basics — Ruby on Rails Guides Unit テストでは次を確認する。 ・Eメール を deliver(送信)した後に、ActionMaile
Railsアプリで、ActiveRecord::Base.transactionを使って、 トランザクションを明示的に張り、異常がある場合にロールバックする、 という実装は大いに有りますよね。 僕はRSpecを使ってテストしています。 RSpecを使って、DBがロールバックされることを確認する方法を書いておきます。 例えば、コントローラに次のような処理を書いたとします。 モデルの変更後、メールを送信する、という処理で、ここでは、メールの送信に失敗した場合は、 変更をロールバックする、という仕様とします。(その仕様は果たして妥当か?はここでは考えない。) def save_and_send_mail(model) begin ActiveRecord::Base.tansaction do model.save! SomeMailer.something.deliver end rescue
This guide explores how to write tests in Rails. After reading this guide, you will know: Rails testing terminology. How to write unit, functional, integration, and system tests for your application. Other popular testing approaches and plugins. 1. Why Write Tests?Writing automated tests can be a faster way of ensuring your code continues to work as expected than manual testing through the browser
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く