Class: Pact::FormDiffer

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

Class Method Summary collapse

Class Method Details

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



6
7
8
9
# File 'lib/pact/shared/form_differ.rb', line 6

def self.call expected, actual, options = {}
  require 'pact/matchers' # avoid recursive loop between this file and pact/matchers
  ::Pact::Matchers.diff to_hash(expected), to_hash(actual), options
end

.decode_www_form(string) ⇒ Object



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

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



19
20
21
22
23
# File 'lib/pact/shared/form_differ.rb', line 19

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

.to_hash(form_body) ⇒ Object



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

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