26

テストのこの部分を実行しています:

 describe Dictionary do
   before do
     @d = Dictionary.new
   end

    it 'can check whether a given keyword exists' do
        @d.include?('fish').should be_false
      end

このコードで:

class Dictionary
  def initialize
    @hash = {}
  end 

  def add(new_entry)
    new_entry.class == String ? @hash[new_entry] = nil : new_entry.each { |noun, definition| @hash[noun] = definition}    
  end 

  def entries
    @hash 
  end 

  def keywords
    @hash.keys
  end

  def include?(word)
    if @hash.has_key?(word)
      true
    else 
      false
    end 
  end 
end 

何が間違っているのかわかりませんが、テストは失敗し続け、次のように言っています。

> 1) Dictionary can check whether a given keyword exists
>      Failure/Error: @d.include?('fish').should be_false
>        expected false to respond to `false?`

正しい答えを出しているように見えるので、エラーに混乱しています。誰かが私のコードの何が問題なのかを教えてくれるのに数分かかることができれば、本当に感謝しています. ありがとうトン。

4

1 に答える 1