This class extracts code snippets by looking at the backtrace of the passed error
# File lib/rspec/core/formatters/snippet_extractor.rb, line 32 32: def lines_around(file, line) 33: if File.file?(file) 34: lines = File.read(file).split("\n") 35: min = [0, line-3].max 36: max = [line+1, lines.length-1].min 37: selected_lines = [] 38: selected_lines.join("\n") 39: lines[min..max].join("\n") 40: else 41: "# Couldn't get snippet for #{file}" 42: end 43: end
# File lib/rspec/core/formatters/snippet_extractor.rb, line 45 45: def post_process(highlighted, offending_line) 46: new_lines = [] 47: highlighted.split("\n").each_with_index do |line, i| 48: new_line = "<span class=\"linenum\">#{offending_line+i-2}</span>#{line}" 49: new_line = "<span class=\"offending\">#{new_line}</span>" if i == 2 50: new_lines << new_line 51: end 52: new_lines.join("\n") 53: end
# File lib/rspec/core/formatters/snippet_extractor.rb, line 15 15: def snippet(backtrace) 16: raw_code, line = snippet_for(backtrace[0]) 17: highlighted = @@converter.convert(raw_code, false) 18: highlighted << "\n<span class=\"comment\"># gem install syntax to get syntax highlighting</span>" if @@converter.is_a?(NullConverter) 19: post_process(highlighted, line) 20: end
# File lib/rspec/core/formatters/snippet_extractor.rb, line 22 22: def snippet_for(error_line) 23: if error_line =~ /(.*):(\d+)/ 24: file = $1 25: line = $2.to_i 26: [lines_around(file, line), line] 27: else 28: ["# Couldn't get snippet for #{error_line}", 1] 29: end 30: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.