我正在学习Ruby和TDD(rspec).
我写了以下测试:
describe is_eligible do
it "returns true if the passed in string is not part of a list" do
result = is_eligible("abc")
result.should eq(false)
end
end
Run Code Online (Sandbox Code Playgroud)
它正在测试以下代码:
def is_eligible(team_name)
array = Array.new
array << "abc" << "def" << "ghi"
if array.include?(team_name)
return false
else
return true
end
end
Run Code Online (Sandbox Code Playgroud)
我收到以下错误,无法找出原因.
*/Users/joel.dehlin/top32/lib/ineligible_teams.rb:6:in`is_eligible':错误的参数个数(0表示1)(ArgumentError)*
任何帮助表示赞赏!
问题是该describe方法需要一个字符串或可以计算为字符串的东西.如果你说"is_eligible"没有引号,它实际上会尝试调用该方法,你会得到错误.
describe "is_eligible" do
it "returns true if the passed in string is not part of a list" do
result = is_eligible("abc")
result.should eq(false)
end
end
Run Code Online (Sandbox Code Playgroud)