Sha256: 269261cfbd835af3afce700ba7b270886d3f2d887117b521f5ef1d457cc143e9

Contents?: true

Size: 1.9 KB

Versions: 2

Compression:

Stored size: 1.9 KB

Contents

describe 'Pacto' do
  let(:contract_path) { 'spec/integration/data/simple_contract.json' }
  let(:strict_contract_path) { 'spec/integration/data/strict_contract.json' }

  before :all do
    WebMock.allow_net_connect!
  end

  context 'Contract validation' do
    before :all do
      @server = Pacto::Server::Dummy.new 8000, '/hello', '{"message": "Hello World!"}'
      @server.start
    end

    after :all do
      @server.terminate
    end

    it 'verifies the contract against a producer' do
      contract = Pacto.load_contracts(contract_path, 'http://localhost:8000')
      expect(contract.validate_all.flatten).to eq([])
    end
  end

  context 'Stubbing a collection of contracts' do
    it 'generates a server that stubs the contract for consumers' do
      contracts = Pacto.load_contracts(contract_path, 'http://dummyprovider.com')
      contracts.stub_all

      response = get_json('http://dummyprovider.com/hello')
      expect(response['message']).to eq 'bar'
    end
  end

  context 'Journey' do
    it 'stubs multiple services with a single use' do
      Pacto.configure do |c|
        c.strict_matchers = false
        c.register_hook Pacto::Hooks::ERBHook.new
      end

      contracts = Pacto.load_contracts 'spec/integration/data/', 'http://dummyprovider.com'
      contracts.stub_all(:device_id => 42)

      login_response = get_json('http://dummyprovider.com/hello')
      expect(login_response.keys).to eq ['message']
      expect(login_response['message']).to be_kind_of(String)

      devices_response = get_json('http://dummyprovider.com/strict')
      expect(devices_response['devices']).to have(2).items
      expect(devices_response['devices'][0]).to eq('/dev/42')
      expect(devices_response['devices'][1]).to eq('/dev/43')
    end
  end

  def get_json(url)
    response = Faraday.get(url) do |req|
      req.headers = {'Accept' => 'application/json' }
    end
    MultiJson.load(response.body)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pacto-0.3.1 spec/integration/e2e_spec.rb
pacto-0.3.0 spec/integration/e2e_spec.rb