Rfm 1.4でテストを実行するには
Rfm 1.4のソースコードファイルが入っているlibディレクトリと同じ階層に、specという名称のディレクトリが存在しますが、このディレクトリにはテスト用のspecファイルが収められています。
Mac OS X Snow LeopardでRfm 1.4.1.2をインストールした場合には、通常「/Library/Ruby/Gems/1.8/gems/lardawge-rfm-1.4.1.2/spec」のディレクトリ以下に下記のファイルが見つかるはずです。
$ ls -R /Library/Ruby/Gems/1.8/gems/lardawge-rfm-1.4.1.2/spec rfm spec_helper.rb /Library/Ruby/Gems/1.8/gems/lardawge-rfm-1.4.1.2/spec/rfm: error_spec.rb record_spec.rb
Rfm 1.4でテストを実行する際、RSpecというテスティングフレームワークが使われます。2011年2月現在、RSpecの最新版はバージョン2.5.1ですが、Rfm 1.4では現在のところRSpec-2ではなくRSpec-1を利用します。このことはspec_helper.rbで「require 'rspec'」ではなく「require 'spec'」と指定されていることから分かります。(RSpecの詳細についてはhttp://rspec.info/を参照してください。なお、RSpec-2.0.0がリリースされたのは昨年の10月です。)
gemコマンドでテストの実行に必要なRSpec-1をインストールできます。2011年2月現在、RSpec-1の最新版はバージョン1.3.1ですので、gemコマンドの-vオプションを使用して、次のようにバージョン1.3.1のRSpecをインストールしましょう。
$ sudo gem install rspec -v 1.3.1
RSpec-1のインストールが無事終われば、準備は完了です。Rfm 1.4のテストを実行するには、次のようにコマンドを実行します。
$ cd /Library/Ruby/Gems/1.8/gems/lardawge-rfm-1.4.1.2 $ spec -c -fs -b -r spec/spec_helper.rb spec/rfm/*.rb Rfm::Error.lookup - should return a default system error if input code is 0 - should return a default system error if input code is 22 - should return a custom message as second argument - should return a script missing error - should return a range validation error - should return unknown error if code not found Rfm::Error.find_by_code - should return a constant representing the error class Rfm::Error.build_message - should return a string with the code and message included - should look like Rfm::Record#[]= - creates a new hash key => value upon instantiation of record - creates a new hash key => value in @mods when modifying an existing record key - raises an Rfm::ParameterError if a key is used that does not exist Rfm::Record#respond_to? - returns true if key is in hash - returns false if key is not in hash Rfm::Record#method_missing getter - will match a method to key in the hash if there is one - will raise NoMethodError if no key present that matches value Rfm::Record#method_missing setter - acts as a setter if the key exists in the hash - will raise NoMethodError if no key present that matches value Finished in 0.042786 seconds 18 examples, 0 failures