class Pact::Matchers::ListDiffFormatter
Attributes
diff[R]
Public Class Methods
call(diff, options = {})
click to toggle source
# File lib/pact/matchers/list_diff_formatter.rb, line 13 def self.call diff, options = {} new(diff, options).call end
new(diff, options = {})
click to toggle source
# File lib/pact/matchers/list_diff_formatter.rb, line 9 def initialize diff, options = {} @diff = diff end
Public Instance Methods
call()
click to toggle source
# File lib/pact/matchers/list_diff_formatter.rb, line 21 def call to_s end
diff_descriptions(obj, path = [], descriptions = [])
click to toggle source
# File lib/pact/matchers/list_diff_formatter.rb, line 29 def diff_descriptions obj, path = [], descriptions = [] case obj when Hash then handle_hash obj, path, descriptions when Array then handle_array obj, path, descriptions when Difference then handle_difference obj, path, descriptions when TypeDifference then handle_mismatched_type obj, path, descriptions when RegexpDifference then handle_mismatched_regexp obj, path, descriptions when NoDiffAtIndex then nil else raise "Invalid diff, expected Hash, Array, NoDiffAtIndex or Difference, found #{obj.class}" end descriptions end
handle_array(array, path, descriptions)
click to toggle source
# File lib/pact/matchers/list_diff_formatter.rb, line 49 def handle_array array, path, descriptions array.each_with_index do | obj, index | diff_descriptions obj, path + [index], descriptions end end
handle_difference(difference, path, descriptions)
click to toggle source
# File lib/pact/matchers/list_diff_formatter.rb, line 55 def handle_difference difference, path, descriptions case difference.expected when Pact::UnexpectedKey then handle_unexpected_key(difference, path, descriptions) when Pact::UnexpectedIndex then handle_unexpected_index(difference, path, descriptions) else case difference.actual when Pact::KeyNotFound then handle_key_not_found(difference, path, descriptions) when Pact::IndexNotFound then handle_index_not_found(difference, path, descriptions) else handle_mismatched_value(difference, path, descriptions) end end end
handle_hash(hash, path, descriptions)
click to toggle source
# File lib/pact/matchers/list_diff_formatter.rb, line 43 def handle_hash hash, path, descriptions hash.each_pair do | key, value | diff_descriptions value, path + [key.inspect], descriptions end end
handle_index_not_found(difference, path, descriptions)
click to toggle source
# File lib/pact/matchers/list_diff_formatter.rb, line 85 def handle_index_not_found difference, path, descriptions descriptions << "\tAt:\n\t\t#{path_to_s(path)}\n\tMissing index with value:\n\t\t#{difference.expected.ai}" end
handle_key_not_found(difference, path, descriptions)
click to toggle source
# File lib/pact/matchers/list_diff_formatter.rb, line 89 def handle_key_not_found difference, path, descriptions descriptions << "\tAt:\n\t\t#{path_to_s(path)}\n\tMissing key with value:\n\t\t#{difference.expected.ai}" end
handle_mismatched_regexp(difference, path, descriptions)
click to toggle source
# File lib/pact/matchers/list_diff_formatter.rb, line 77 def handle_mismatched_regexp difference, path, descriptions descriptions << "\tAt:\n\t\t#{path_to_s(path)}\n\tExpected to match:\n\t\t#{difference.expected.inspect}\n\tActual:\n\t\t#{difference.actual.ai}" end
handle_mismatched_type(difference, path, descriptions)
click to toggle source
# File lib/pact/matchers/list_diff_formatter.rb, line 81 def handle_mismatched_type difference, path, descriptions descriptions << "\tAt:\n\t\t#{path_to_s(path)}\n\tExpected type:\n\t\t#{difference.expected}\n\tActual type:\n\t\t#{difference.actual}" end
handle_mismatched_value(difference, path, descriptions)
click to toggle source
# File lib/pact/matchers/list_diff_formatter.rb, line 73 def handle_mismatched_value difference, path, descriptions descriptions << "\tAt:\n\t\t#{path_to_s(path)}\n\tExpected:\n\t\t#{difference.expected.ai}\n\tActual:\n\t\t#{difference.actual.ai}" end
handle_unexpected_index(difference, path, descriptions)
click to toggle source
# File lib/pact/matchers/list_diff_formatter.rb, line 69 def handle_unexpected_index difference, path, descriptions descriptions << "\tAt:\n\t\t#{path_to_s(path)}\n\tArray contained unexpected item:\n\t\t#{difference.actual.ai}" end
handle_unexpected_key(difference, path, descriptions)
click to toggle source
# File lib/pact/matchers/list_diff_formatter.rb, line 93 def handle_unexpected_key difference, path, descriptions descriptions << "\tAt:\n\t\t#{path_to_s(path)}\n\tHash contained unexpected key with value:\n\t\t#{difference.actual.ai}" end
path_to_s(path)
click to toggle source
# File lib/pact/matchers/list_diff_formatter.rb, line 97 def path_to_s path "[" + path.join("][") + "]" end
to_hash()
click to toggle source
# File lib/pact/matchers/list_diff_formatter.rb, line 17 def to_hash diff end
to_s()
click to toggle source
# File lib/pact/matchers/list_diff_formatter.rb, line 25 def to_s diff_descriptions(diff).join("\n") end