Sha256: 5086169222d1a2fe4c0c04d3fec82915153e84a4cce305d2679ddc3dd1ed9e16

Contents?: true

Size: 1.65 KB

Versions: 3

Compression:

Stored size: 1.65 KB

Contents

# -*- encoding : utf-8 -*-
describe Pacto::Hooks::ERBHook do
  describe '#process' do
    let(:req) do
      OpenStruct.new(headers: { 'User-Agent' => 'abcd' })
    end
    let(:converted_req) do
      { 'HEADERS' => { 'User-Agent' => 'abcd' } }
    end
    let(:res) do
      Pacto::PactoResponse.new(
        status: 200,
        body: 'before'
      )
    end

    before do
    end

    context 'no matching contracts' do
      it 'binds the request' do
        contracts = Set.new
        mock_erb(req: converted_req)
        described_class.new.process contracts, req, res
        expect(res.body).to eq('after')
      end
    end

    context 'one matching contract' do
      it 'binds the request and the contract\'s values' do
        contract = OpenStruct.new(values: { max: 'test' })
        contracts = Set.new([contract])
        mock_erb(req: converted_req, max: 'test')
        described_class.new.process contracts, req, res
        expect(res.body).to eq('after')
      end
    end

    context 'multiple matching contracts' do
      it 'binds the request and the first contract\'s values' do
        contract1 = OpenStruct.new(values: { max: 'test' })
        contract2 = OpenStruct.new(values: { mob: 'team' })
        res = Pacto::PactoResponse.new(
          status: 200,
          body: 'before'
        )
        mock_erb(req: converted_req, max: 'test')
        contracts = Set.new([contract1, contract2])
        described_class.new.process contracts, req, res
        expect(res.body).to eq('after')
      end
    end
  end

  def mock_erb(hash)
    expect_any_instance_of(Pacto::ERBProcessor).to receive(:process).with('before', hash).and_return('after')
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pacto-0.4.0.rc3 spec/unit/pacto/hooks/erb_hook_spec.rb
pacto-0.4.0.rc2 spec/unit/pacto/hooks/erb_hook_spec.rb
pacto-0.4.0.rc1 spec/unit/pacto/hooks/erb_hook_spec.rb