如何从rspec测试中调用方法

时间:2012-12-22 19:49:51

标签: ruby rspec tdd

我正在学习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)*

感谢任何帮助!

1 个答案:

答案 0 :(得分: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
相关问题