Class: Pact::FormDiffer

Inherits:
Object
  • Object
show all
Extended by:
Matchers
Defined in:
lib/pact/shared/form_differ.rb

Constant Summary

Constants included from Matchers

Matchers::DEFAULT_OPTIONS, Matchers::NO_DIFF, Matchers::NO_DIFF_AT_INDEX

Class Method Summary collapse

Methods included from Matchers

diff, type_diff

Class Method Details

.call(expected, actual, options = {}) ⇒ Object



9
10
11
# File 'lib/pact/shared/form_differ.rb', line 9

def self.call expected, actual, options = {}
  diff to_hash(expected), to_hash(actual), options
end

.decode_www_form(string) ⇒ Object



27
28
29
30
31
32
# File 'lib/pact/shared/form_differ.rb', line 27

def self.decode_www_form string
  URI.decode_www_form(string).each_with_object({}) do | (key, value), hash |
    hash[key] ||= []
    hash[key] << value
  end
end

.ensure_values_are_arrays(hash) ⇒ Object



21
22
23
24
25
# File 'lib/pact/shared/form_differ.rb', line 21

def self.ensure_values_are_arrays hash
  hash.each_with_object({}) do | (key, value), hash |
    hash[key.to_s] = [*value]
  end
end

.to_hash(form_body) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/pact/shared/form_differ.rb', line 13

def self.to_hash form_body
  if form_body.is_a?(Hash)
    ensure_values_are_arrays form_body
  else
    decode_www_form form_body
  end
end