我在测试中用
dictionary.stub(:words).and_return
(%w{cat,dog,fish,plane,rock,dig,dug,cut,cuts,put,puts,putting,ruby,use,GO,IT})
这样我就不必使用
Dictionary.load_system_dictionary
填充的方法
@words
我可以把
words
方法
现在我想测试另一个名为
contains_word(word)
:
def contains_word(word)
@words.map(&:upcase).join.include?(word.upcase)
end
但问题是
@单词
通常由
字典.load_system_directory
方法,但我不想使用它,因为它有90k条记录,但如果没有它
File.open(words_file).each {|word| @words << word}
我的
@单词
属性未填充。
如果我愿意
dictionary.load_system_dictionary
对于真正的字典,测试通过
但如果我用
dictionary.stub(:words).and_return
(%w{cat,dog,fish,plane,rock,dig,dug,cut,cuts,put,puts,puttingzaq1,ruby,use,GO,IT})
我明白了
Failure/Error: expect(dictionary.contains_word('IT')).to be true
expected #<TrueClass:2> => true
got #<FalseClass:0> => false
btw字典最初设置为
let(:dictionary) {Dictionary.new}