Sha256: fd826004f777c60207f2a3de4e1bfad5cc7d6c455d1420c291a8b252a70e0426

Contents?: true

Size: 1022 Bytes

Versions: 1

Compression:

Stored size: 1022 Bytes

Contents

# -*- encoding : utf-8 -*-
require 'pacto'
Pacto.configure do |c|
  c.contracts_path = 'contracts'
end
Pacto.validate!

# You can create a custom cop that investigates the request/response and sees if it complies with a
# contract. The cop should return a list of citations if it finds any problems.
class MyCustomCop
  def investigate(_request, _response, contract)
    citations = []
    citations << 'Contract must have a request schema' if contract.request.schema.empty?
    citations << 'Contract must have a response schema' if contract.response.schema.empty?
    citations
  end
end

Pacto::Cops.active_cops << MyCustomCop.new

contracts = Pacto.load_contracts('contracts', 'http://localhost:5000')
contracts.stub_providers
puts contracts.simulate_consumers

# Or you can completely replace the default set of validators
Pacto::Cops.registered_cops.clear
Pacto::Cops.register_cop Pacto::Cops::ResponseBodyCop

contracts = Pacto.load_contracts('contracts', 'http://localhost:5000')
puts contracts.simulate_consumers

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pacto-0.4.0.rc1 samples/cops.rb