2008-08-01から1ヶ月間の記事一覧

「初めてのRuby」の復習をexpectationsで(変数と式)

# -*- coding: utf-8 -*- require "rubygems" require "expectations" #6章 変数と式 Expectations do expect [true, true] do a = "aaa" b = a [a == b, a.equal?(b)] end expect [true, false] do a = "aaa" b = "aaa" [a == b, a.equal?(b)] end #多値 ex…

「初めてのRuby」の復習をexpectationsで(メソッド)

# -*- coding: utf-8 -*- require "rubygems" require "expectations" #7章 メソッド Expectations do #多値 expect 2 do def foo; return 1, 2, 3; end a, b, c = foo b end expect [1, 2, 3] do def foo; return 1, 2, 3; end foo end #クロージャ expect …

「初めてのRuby」の復習をexpectationsで(オブジェクトとクラス)

# -*- coding: utf-8 -*- require "rubygems" require "expectations" #8章 オブジェクトとクラス Expectations do #加算メソッドの上書き expect 3 do class Fixnum alias original_add + def +(rhs); original_add(rhs).succ; end end 1 + 1 end #上書きの…

「初めてのRuby」の復習(入出力)

入出力はexpectationsに書き下すのが面倒そうなので普通に例文を写経。ユニットテストだと、こういう外部リソースとのアクセスが絡むとどう扱うか悩みます。DBアクセス(接続確立〜データ取得)、ファイル情報取得、ログ出力、認証付のWebアクセス・・・セオリ…

「初めてのRuby」の復習をexpectationsで(配列とハッシュ・文字列)

「初めてのRuby」を読みました。 特異メソッド・特異クラス周りについては馴染みきっていない印象です・・・知らなかったときよりは理解が深まりましたが。 その他、Rubyでの書き方や細かな動きの部分で知らないことが多く、ためになりました。 この「初めて…

Rubyテスティングフレームワーク・expectations

http://expectations.rubyforge.org/files/README.html http://d.hatena.ne.jp/keyword/expectations (via http://d.hatena.ne.jp/rubikitch/20080508/ruby187)Rubyのテスティングフレームワークであるexpectationsを動かしてみたのでメモ。 このテスティン…