#author("2021-11-27T11:55:49+00:00","default:hotate","hotate") #author("2023-10-22T09:42:48+00:00;2021-11-27T11:55:49+00:00","default:hotate","hotate") #contents &tag(Ruby, ユニットテスト, スタブ); &tag(Ruby,ユニットテスト,スタブ); * 標準 [#bf85e5a3] - [[Ruby標準のテスティングフレームワークで手軽にテストコードを書く方法 - Qiita>http://qiita.com/jnchito/items/ff4f7a23addbd8dbc460]] 簡単なコードであれば、テストコードも簡単なものになるのでassert_equalが使えれば十分だったりします。 - [[Is it idiomatic Ruby to add an assert( ) method to Ruby's Kernel class? - Stack Overflow>https://stackoverflow.com/questions/147969/is-it-idiomatic-ruby-to-add-an-assert-method-to-rubys-kernel-class]] No it's not a best practice. The best analogy to assert() in Ruby is just raising raise "This is wrong" unless expr - [[jorgemanrubia/solid_assert: Assert utility for ruby>https://github.com/jorgemanrubia/solid_assert]] solid_assert is a simple implementation of an assert utility in Ruby. It lets you write tests for your assumptions while coding. * フレームワーク [#c2a96a29] - [[test-unit - Ruby用単体テストフレームワーク>https://test-unit.github.io/ja/#test-unit]] test-unitはRuby用のxUnit系の単体テストフレームワークです。 - [[Rubyのテスティングフレームワークの歴史(2014年版) - ククログ(2014-11-06)>http://www.clear-code.com/blog/2014/11/6.html]] Ruby 2.2にはRuby 1.9.1のときに外されたtest-unitというテスティングフレームワークが再びバンドルされる予定です。Rubyのテスティングフレームワーク周りに詳しくない人にはよくわからない状況でしょう。そこで、Rubyのテスティングフレームワークの歴史を説明することで状況を整理します。 - [[Minimalicious testing in Ruby 1.9 with MiniTest - Random notes by Arvid Andersson>http://blog.arvidandersson.se/2012/03/28/minimalicous-testing-in-ruby-1-9]] Since ruby 1.9 the ruby standard library has included a testing framework called MiniTest, it is a modern and lightweight replacement for ruby 1.8's Test::Unit framework. - [[「Rubyベストプラクティス」を読む1 - saliy1の日記>http://d.hatena.ne.jp/saliy1/20100724/1279980413]] putsやgetsを使っているaskメソッドをテストするには、IOオブジェクトのように振舞うオブジェクトを使えばいい。 ** WebMock [#k2e24947] - [[Rails開発でWebMockを使ってAPIアクセスをスタブ化する | Developers.IO>http://dev.classmethod.jp/server-side/rails-development-with-webmock/]] (2016/5/31) WebMockというGemを使うと、外部へのHTTPリクエストをスタブ化してくれるので、開発が非常にやりやすくなります。