【发布时间】:2012-12-05 16:57:51
【问题描述】:
我有一个方法,如果它做正确的事情,我想测试不同的参数。 我现在正在做的是
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
但是,一遍又一遍地重复这个方法真的不是那么干......有什么更好的方法来完成这个?更多的是 cucumber 的“table”选项的作用(它只是帮助方法的正确行为,所以使用 cucumber 似乎不正确)。
【问题讨论】:
标签: ruby-on-rails rspec tdd