私はこのような基本的な構造を持っています
class Automobile
def some_method
# this code sets up structure for child classes... I want to test this
end
end
class Car < Automobile
def some_method
super
# code specific to Car... it's tested elsewhere so I don't want to test this now
end
end
class CompactCar < Car
def some_method
super
# code specific to CompactCar... I want to test this
end
end
からコードを実行せずCompactCar
にテストするための推奨される方法は何ですか? 子クラスに必要な構造を提供するので、常にそれをテストしたいのですが、機能は他の場所でテストされており、努力を繰り返したくありません。Automobile
Car
Automobile#some_method
Car's
class_eval
1 つの解決策はoverwriteを使用することCar#some_method
ですが、これは理想的ではありません。これは、上書きされたメソッドがテスト中にそのまま残るためです (元のライブラリ ファイルを setup/teardown メソッドで再ロードしない限り...一種の醜い解決策です) )。また、単に への呼び出しをスタブ化してCar#some_method
も機能しないようです。
これを行うためのよりクリーンな/より一般的に受け入れられている方法はありますか?