正しいことを行うかどうか、さまざまなパラメーターについてテストしたいメソッドがあります。私が今していることは、
def test_method_with(arg1, arg2, match)
it "method should #{match.inspect} when arg2 = '#{arg2}'" do
method(arg1, FIXEDARG, arg2).should == match
end
end
context "method with no info in arg1" do
before (:each) do
@ex_string = "no info"
end
test_method_with(@ex_string, "foo").should == "res1"}
test_method_with(@ex_string, "bar").should == "res1"}
test_method_with(@ex_string, "foobar").should == "res1"}
test_method_with(@ex_string, "foobar2").should == "res2"}
test_method_with(@ex_string, "barbar").should == "res2"}
test_method_with(@ex_string, nil).should == nil}
end
しかし、これは実際には、この方法を何度も繰り返すほどDRYではありません...これを達成するためのより良い方法は何でしょうか? キュウリの「テーブル」オプションがそれを行う方法の詳細 (これはヘルパー メソッドのほぼ正しい動作であるため、キュウリを使用することは正しくないようです)。