class RSpec::Support::HunkGenerator

@private

Public Class Methods

new(actual, expected) click to toggle source
# File lib/rspec/support/hunk_generator.rb, line 8
def initialize(actual, expected)
  @actual = actual
  @expected = expected
end

Public Instance Methods

hunks() click to toggle source
# File lib/rspec/support/hunk_generator.rb, line 13
def hunks
  @file_length_difference = 0
  @hunks ||= diffs.map do |piece|
    build_hunk(piece)
  end
end

Private Instance Methods

actual_lines() click to toggle source
# File lib/rspec/support/hunk_generator.rb, line 30
def actual_lines
  @actual.split("\n").map! { |e| e.chomp }
end
build_hunk(piece) click to toggle source
# File lib/rspec/support/hunk_generator.rb, line 34
def build_hunk(piece)
  Diff::LCS::Hunk.new(
    expected_lines, actual_lines, piece, context_lines, @file_length_difference
  ).tap do |h|
    @file_length_difference = h.file_length_difference
  end
end
context_lines() click to toggle source
# File lib/rspec/support/hunk_generator.rb, line 42
def context_lines
  3
end
diffs() click to toggle source
# File lib/rspec/support/hunk_generator.rb, line 22
def diffs
  Diff::LCS.diff(expected_lines, actual_lines)
end
expected_lines() click to toggle source
# File lib/rspec/support/hunk_generator.rb, line 26
def expected_lines
  @expected.split("\n").map! { |e| e.chomp }
end