Rspec code is
it "calls calculate_word_frequency when created" do
expect_any_instance_of(LineAnalyzer).to receive(:calculate_word_frequency)
LineAnalyzer.new("", 1)
end
Code of class is
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
This test gives an error
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
How I resolve this error.How I pass this test?
calculate_work_frequencyshould be called during initialization. Whether or not that's correct behavior--we have no clue.