我有一個方法,我想測試不同的參數,如果它做的是正確的。 我在做什麼,現在是Rspec-Rails:測試一個有很多參數組合的方法
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
但這真的不是這麼幹的過度重複的方法,一遍又一遍......這將是一個更好的方式來做到這一點?更多的方式黃瓜的「表」選項(它只是一個輔助方法的正確行爲,所以使用黃瓜似乎不正確)。