読み進めると、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
Minitest is a beautifully made test suite for writing tests to verify your expectations from your code base. According to the website, it "provides a complete suite of testing facilities supporting TDD, BDD, mocking, and benchmarking." The way it's implemented is rather straightforward, as you can see in creator Ryan Davis' walk-through of Minitest's design/implementation. Fundamentally, it has be
minitest には標準で mock や stub の機能が付いています。それらの挙動について学んだのでメモ。 コード例 下記のような Person クラスと Whisky クラスがあるとします。これらについて minitest の mock と stub を使ってテストを書いてみます。 class Person def eat(food) food.taste end def drink(whisky) whisky.alcohol.upcase end end class Whisky def alcohol # まだ実装されていない end end mock minitest では下記のように mock を書きます。 describe Person do subject { Person.new } describe '#eat' do it '引数にとったオブジェクトの #tas
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
In his article on Unit Testing, Martin Fowler mentions that what a unit actually is can change depending on what school of thought you come from. Many from the object-oriented world consider the Class as the unit, whereas those in the functional programming world consider the Function the unit. Even though Ruby is an object-oriented language, I tend to see the method/function as the unit. This is
こんにちは。 DMM.comラボでプラットフォームの開発をしておりますいっちーです。 PHPやJAVAを使うことが多いDMMですが、 最近ではRubyやNode.jsなどチームやプロジェクトごとに様々な言語を使うようになってきました。 今回はRubyに関してのブログを書きます。 Rubyのテストフレームワークは色々ありますが、その中のminitest というフレームワークのプラグインとしてminitest-names というものを作成したのでgemを公開しました。 ソースコードはdmm.com laboのgithubリポジトリにあります。 作成したのはプラグインですがgem形式なのでrubygems.orgにも置きました。 どんな機能なのか? 端的に説明するとテストケース名を複数指定して、それらを実行するものです。 minitestのテストは以下のようにtest_で始まる関数で、実行時にこ
assert assert_block assert_equal assert_no_match assert_not_equal assert_not_nil assert_not_same assert_not_send assert_nothing_raised assert_nothing_thrown assert_raise assert_raise_with_message assert_respond_to assert_send assert_throw assert(test, [failure_message]) assert_block( failure_message = nil ) assert_equal( expected, actual, failure_message = nil ) assert_no_match( regexp, string, fa
← Exceptions | RubyDoc → Unit testing is a great way to catch errors early in the development process, if you dedicate time to writing appropriate and useful tests. As in other languages, Ruby provides a framework in its standard library for setting up, organizing, and running tests called Test::Unit. There are other very popular testing frameworks, rspec and cucumber come to mind. Specifically, T
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ページを開く