我有一個RSpec測試如下:Rspec的合格測試
it "calculates highest count words across lines to be will, it, really" do
solution.analyze_file
expect(solution.highest_count_words_across_lines).to be nil
solution.calculate_line_with_highest_frequency
words_found = solution.highest_count_words_across_lines.map(&:highest_wf_words).flatten
expect(words_found).to match_array ["will", "it", "really"]
end
它給出了一個錯誤
Solution#calculate_line_with_highest_frequency calculates highest count words across lines to be will, it, really
Failure/Error: words_found solution.highest_count_words_across_lines.map(&:highest_wf_words).flatten
NoMethodError:
undefined method `highest_wf_words' for "really":String
# ./spec/solution_spec.rb:38:in `map'
# ./spec/solution_spec.rb:38:in `block (3 levels) in <top (required)>'
在另一方面,如果我寫這個測試沒有
.map(&:highest_wf_words).flatten
然後它通過。
@highest_count_words_across_lines = ["really","will","it"]
我怎樣才能使此測試通過,而includding映射:
.map(&:highest_wf_words).flatten?
你能正確格式化你的代碼/錯誤信息嗎?並重新說明你的問題標題? – onebree
我更新我的問題。現在看到 –
有錯誤提示您正在調用'''''真高'_wf_words'。 highest_wf_words()方法的樣子是什麼? – 7stud