class Grntest::DiffReporter
Public Class Methods
new(expected, actual)
click to toggle source
# File lib/grntest/diff-reporter.rb, line 21 def initialize(expected, actual) @expected = expected @actual = actual end
Public Instance Methods
report()
click to toggle source
# File lib/grntest/diff-reporter.rb, line 26 def report expected_lines = @expected.lines.collect(&:chomp) actual_lines = @actual.lines.collect(&:chomp) diffs = Diff::LCS.diff(expected_lines, actual_lines) return if diffs.empty? report_expected_label("(expected)") report_actual_label("(actual)") context_n_lines = 3 previous_hunk = nil file_length_diff = 0 diffs.each do |diff| begin hunk = Diff::LCS::Hunk.new(expected_lines, actual_lines, diff, context_n_lines, file_length_diff) next if previous_hunk.nil? next if hunk.merge(previous_hunk) report_hunk(previous_hunk) ensure previous_hunk = hunk end end report_hunk(previous_hunk) end
Private Instance Methods
actual_mark()
click to toggle source
# File lib/grntest/diff-reporter.rb, line 62 def actual_mark "+" end
expected_mark()
click to toggle source
# File lib/grntest/diff-reporter.rb, line 58 def expected_mark "-" end
report_actual_label(content)
click to toggle source
# File lib/grntest/diff-reporter.rb, line 70 def report_actual_label(content) puts("#{actual_mark * 3} #{content}") end
report_expected_label(content)
click to toggle source
# File lib/grntest/diff-reporter.rb, line 66 def report_expected_label(content) puts("#{expected_mark * 3} #{content}") end
report_hunk(hunk)
click to toggle source
# File lib/grntest/diff-reporter.rb, line 74 def report_hunk(hunk) puts(hunk.diff(:unified)) end