Sha256: 0b7c2742c7c9076fe844a9aa5d38fa2a1203d91752776d076e833ff2db16edfb
Contents?: true
Size: 1.08 KB
Versions: 1
Compression:
Stored size: 1.08 KB
Contents
require 'method_source' module Pork module ShowSource def show_source test, err source = test.source sopath = "#{test.source_location.first}:" lowers = test.source_location.last uppers = lowers + source.size lineno = reject_pork(test, err).find do |backtrace| # find the line from the test source, exclude everything else next unless backtrace.start_with?(sopath) number = backtrace[/(?<=\.rb:)\d+/].to_i break number if number >= lowers && number < uppers end return '' unless lineno # TODO: error might be coming from before block lowerl = lineno - lowers upperl = MethodSource.expression_at(source, lowerl + 1). count("\n") + lowerl indent = source[/^\s*/].size result = source.each_line.with_index.map do |source_line, index| line = source_line[indent..-1] || "\n" if index >= lowerl && index < upperl highlight_line(" => #{line}") else backlight_line(" #{line}") end end.join "\n#{result.chomp}" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pork-1.2.4 | lib/pork/extra/show_source.rb |