Class: Pact::Matchers::MultipartFormDiffFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/pact/matchers/multipart_form_diff_formatter.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of MultipartFormDiffFormatter.



8
9
10
11
12
13
14
# File 'lib/pact/matchers/multipart_form_diff_formatter.rb', line 8

def initialize diff, options = {}
  @options = options
  @body_diff = diff[:body]
  @non_body_diff = diff.reject{ |k, v| k == :body }
  @colour = options.fetch(:colour, false)
  @differ = Pact::Matchers::Differ.new(@colour)
end

Class Method Details

.call(diff, options = {}) ⇒ Object



16
17
18
# File 'lib/pact/matchers/multipart_form_diff_formatter.rb', line 16

def self.call diff, options = {}
  new(diff, options).call
end

Instance Method Details

#body_diff_stringObject



32
33
34
35
36
37
38
# File 'lib/pact/matchers/multipart_form_diff_formatter.rb', line 32

def body_diff_string
  if @body_diff
    @differ.diff_as_string(@body_diff.expected, @body_diff.actual)
  else
    ""
  end
end

#callObject



20
21
22
# File 'lib/pact/matchers/multipart_form_diff_formatter.rb', line 20

def call
  Pact::Matchers::UnixDiffFormatter::MESSAGES_TITLE + "\n" + non_body_diff_string + "\n" + body_diff_string
end

#non_body_diff_stringObject



24
25
26
27
28
29
30
# File 'lib/pact/matchers/multipart_form_diff_formatter.rb', line 24

def non_body_diff_string
  if @non_body_diff.any?
    Pact::Matchers::ExtractDiffMessages.call(@non_body_diff).collect{ | message| "* #{message}" }.join("\n")
  else
    ""
  end
end