非常によく似たクラスを定義するrubyファイル(、、)がいくつかありa.rbますb.rb。c.rb(彼らは同じことをテストする必要があります)
これらのサブクラスをテストするための単体テストを作成し、各クラスのコンテキストをプログラムで生成しました(以下を参照)。代わりに、プログラムでテストクラス全体を作成する必要がありますか?もしそうなら、なぜそしてどのように?
単体テスト拡張機能を使用しているshouldaので、ファイルは次のようになります。
a.rb
class ItsA
def number
1123
end
end
すぐに戻る
class ItsB
def number
6784
end
end
test_letters.rb
require 'rubygems'
require 'test/unit'
require 'shoulda'
class LettersTest < Test::Unit::TestCase
Dir.glob('letters/*.rb') do |letter|
context "The #{letter} letter file"
setup do
# Here I require the ruby file and allocate
# @theclass to be an instance of the class in the file.
# I'm actually testing JavaScript using Harmony, but
# putting those details in might complicate my question.
end
should "return a number" do
assert @theclass.number.is_a? Number
end
end
end
これはかなりうまく機能しますが、代わりに他のジゲリーポケリーを実行して、自動的に作成などを行う必要がありますLetterATestかLetterBTest?もしそうなら、あなたはそれをどのように行いますか、そしてその理由は何ですか?