【发布时间】:2015-11-23 20:30:00
【问题描述】:
我有一个 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"]
我怎样才能使这个测试通过,同时包括映射:
.map(&:highest_wf_words).flatten?
【问题讨论】:
-
您能否正确格式化您的代码/错误消息?并改写你的问题标题?
-
我更新了我的问题。请立即查看
-
有错误说您正在调用
'really'.highest_wf_words。 high_wf_words() 方法长什么样子? -
请贴出
highest_count_words_across_lines和highest_wf_words方法的代码。而且,在未来,使用更多更短的方法名称 -
这两个都是实例变量
标签: ruby dictionary rspec