Sha256: 160c24d367058606513ff3cbfbd8433c5b634cecec346d91b9ba45f57c81f0ef
Contents?: true
Size: 1.53 KB
Versions: 61
Compression:
Stored size: 1.53 KB
Contents
module Pact module Provider module Help class PactDiff class PrintPactDiffError < StandardError; end attr_reader :pact_json, :output def initialize pact_json @pact_json = pact_json end def self.call pact_json new(pact_json).call end def call begin if diff_rel && diff_url header + "\n" + get_diff end rescue PrintPactDiffError => e return e.message end end private def header "The following changes have been made since the previous distinct version of this pact, and may be responsible for verification failure:\n" end def pact_hash @pact_hash ||= json_load(pact_json) end def links pact_hash['_links'] || pact_hash['links'] end def diff_rel return nil unless links key = links.keys.find { | key | key =~ /diff/ && key =~ /distinct/ && key =~ /previous/} key ? links[key] : nil end def diff_url diff_rel['href'] end def get_diff begin open(diff_url) { | file | file.read } rescue StandardError => e raise PrintPactDiffError.new("Tried to retrieve diff with previous pact from #{diff_url}, but received response code #{e}.") end end def json_load json JSON.load(json, nil, { max_nesting: 50 }) end end end end end
Version data entries
61 entries across 61 versions & 1 rubygems