Class: Pact::Matchers::UnixDiffFormatter

Inherits:
Object
  • Object
show all
Includes:
JRubySupport
Defined in:
lib/pact/matchers/unix_diff_formatter.rb

Defined Under Namespace

Classes: NoDifferenceDecorator, RegexpDecorator

Class Method Summary collapse

Instance Method Summary collapse

Methods included from JRubySupport

#fix_blank_lines_in_empty_hashes

Constructor Details

#initialize(diff, options = {}) ⇒ UnixDiffFormatter

Returns a new instance of UnixDiffFormatter.



11
12
13
14
15
16
# File 'lib/pact/matchers/unix_diff_formatter.rb', line 11

def initialize diff, options = {}
  @diff = diff
  @colour = options.fetch(:colour, false)
  @include_explanation = options.fetch(:include_explanation, true)
  @differ = Pact::Matchers::Differ.new(@colour)
end

Class Method Details

.call(diff, options = {colour: Pact.configuration.color_enabled}) ⇒ Object



18
19
20
# File 'lib/pact/matchers/unix_diff_formatter.rb', line 18

def self.call diff, options = {colour: Pact.configuration.color_enabled}
  new(diff, options).call
end

Instance Method Details

#callObject



22
23
24
# File 'lib/pact/matchers/unix_diff_formatter.rb', line 22

def call
  to_s
end

#to_sObject



26
27
28
29
30
31
32
# File 'lib/pact/matchers/unix_diff_formatter.rb', line 26

def to_s
  expected = generate_string(diff, :expected)
  actual = generate_string(diff, :actual)
  suffix = @include_explanation ?  "\n" + key : ''
  string_diff = remove_comma_from_end_of_arrays(@differ.diff_as_string(actual, expected).lstrip)
  string_diff + suffix
end