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':引数の数が間違っています(1の場合は0)(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 に答える