2

我正在同时学习 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

它正在测试以下代码:

def is_eligible(team_name)
  array = Array.new
  array << "abc" << "def" << "ghi"
  if array.include?(team_name)
    return false
  else
    return true
  end
end

我收到以下错误,但找不到原因。

*/Users/joel.dehlin/top32/lib/ineligible_teams.rb:6:in `is_eligible':参数数量错误(0 代表 1)(ArgumentError)*

任何帮助表示赞赏!

4

1 回答 1

5

问题是该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
于 2012-12-22T19:59:01.190 回答