Sha256: c2935629bbce50036c4e848ff68c3e82a96c168cb6b4d09f5779a0d34183964a

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

require 'pact/consumer'
require 'pact/consumer/rspec'
load 'pact/consumer/world.rb'
require 'faraday'

describe "A service consumer side of a pact", :pact => true  do
  context "with a provider state" do
    before do
      Pact.clear_configuration

      Pact.service_consumer "Consumer" do
        has_pact_with "Zebra Service" do
          mock_service :zebra_service do
            verify false
            port 1235
          end
        end
      end
    end

    let(:body) { 'That is some good Mallory.' }

    it "goes like this" do
      zebra_service.
        given(:the_zebras_are_here).
      upon_receiving("a retrieve Mallory request").with({
                                                          method: :get,
                                                          path: '/mallory',
                                                          headers: {'Accept' => 'text/html'}
      }).
      will_respond_with({
                          status: 200,
                          headers: { 'Content-Type' => 'text/html' },
                          body: Pact::Term.new(matcher: /Mallory/, generate: body)
      })

      response = Faraday.get(zebra_service.mock_service_base_url + "/mallory", nil, {'Accept' => 'text/html'})
      expect(response.body).to eq body

      interactions = Pact::ConsumerContract.from_json(zebra_service.write_pact).interactions
      expect(interactions.first.provider_state).to eq("the_zebras_are_here")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pact-1.4.0.rc4 spec/integration/consumer_with_a_provider_state_spec.rb
pact-1.4.0.rc3 spec/integration/consumer_with_a_provider_state_spec.rb