Sha256: 908288baf420ad1b9b508c5c250eb59675c6c6d93563865776f96e620f71b03c

Contents?: true

Size: 1.45 KB

Versions: 10

Compression:

Stored size: 1.45 KB

Contents

require "approvals/rspec"
require "pact/support"
require "yaml"

class YamlFormat < Approvals::Writers::TextWriter
  def format(data)
    data.to_yaml
  end

  def filter(data)
    # Custom data filtering here
  end
end

Approvals.configure do |c|
  c.approvals_path = "spec/fixtures/approvals/"
end

def print_diff(exception)
  parts = exception.message.split('"')
  received_file = parts[1]
  approved_file = parts[3]
  if File.exist?(received_file) && File.exist?(approved_file)
    received_hash = JSON.parse(File.read(received_file))
    approved_hash = JSON.parse(File.read(approved_file))
    diff = Pact::Matchers.diff(approved_hash, received_hash)
    puts Pact::Matchers::UnixDiffFormatter.call(diff)
  end
end

module MatrixQueryContentForApproval
  def matrix_query_content_for_approval(result)
    {
      "deployable" => result.deployment_status_summary.deployable?,
      "reasons" => result.deployment_status_summary.reasons.collect(&:class).collect(&:name).sort
    }
  end
end

RSpec.configure do | config |
  config.after(:each) do | example |
    if example.exception.is_a?(Approvals::ApprovalError)
      print_diff(example.exception)
    end
  end

  def file_name_to_approval_name(filename)
    sanitize_filename(filename.split("spec/lib/pact_broker/", 2).last.gsub(".rb", ""))
  end

  def sanitize_filename(filename)
    filename.encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: "�").strip.tr("\u{202E}%$|:;/\t\r\n\\", "-")
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
pact_broker-2.89.1 spec/support/approvals.rb
pact_broker-2.89.0 spec/support/approvals.rb
pact_broker-2.88.0 spec/support/approvals.rb
pact_broker-2.87.0 spec/support/approvals.rb
pact_broker-2.86.0 spec/support/approvals.rb
pact_broker-2.85.1 spec/support/approvals.rb
pact_broker-2.85.0 spec/support/approvals.rb
pact_broker-2.84.0 spec/support/approvals.rb
pact_broker-2.83.0 spec/support/approvals.rb
pact_broker-2.82.0 spec/support/approvals.rb