我正在运行这部分测试:
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
Run Code Online (Sandbox Code Playgroud)
使用此代码:
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
Run Code Online (Sandbox Code Playgroud)
我不知道我做错了什么,但我的测试仍然失败并说:
> 1) Dictionary can check whether a given keyword exists
> Failure/Error: …Run Code Online (Sandbox Code Playgroud)