Rspec的代码是一流的Rspec的错误
it "calls calculate_word_frequency when created" do
expect_any_instance_of(LineAnalyzer).to receive(:calculate_word_frequency)
LineAnalyzer.new("", 1)
end
代码是
def initialize(content,line_number)
@content = content
@line_number = line_number
end
def calculate_word_frequency
h = Hash.new(0)
abc = @content.split(' ')
abc.each { |word| h[word.downcase] += 1 }
sort = h.sort_by {|_key, value| value}.reverse
puts @highest_wf_count = sort.first[1]
a = h.select{|key, hash| hash == @highest_wf_count }
puts @highest_wf_words = a.keys
end
这个测试提供了一个错误
LineAnalyzer calls calculate_word_frequency when created Failure/Error: DEFAULT_FAILURE_NOTIFIER = lambda { |failure, _opts| raise failure } Exactly one instance should have received the following message(s) but didn't: calculate_word_frequency
我如何解决这个error.How我通过这个测试?
这不是一个错误,这是一个失败的测试,这是RSpec的一个完全正常的部分。 – meagar
我如何通过它.. –
修复您的代码或您的规范。根据你的规范,应该在初始化期间调用'calculate_work_frequency'。无论这是否是正确的行为 - 我们不知道。 –