Sha256: 321b421f96da29c72c636aec46b24ce009ce5feaf1f4080493b7c5643d4aa191

Contents?: true

Size: 1.17 KB

Versions: 10

Compression:

Stored size: 1.17 KB

Contents

require 'pact/consumer/rspec'
require './spec/support/active_support_if_configured'

Pact.service_consumer "Standalone Consumer" do
  has_pact_with "Standalone Provider" do
    mock_service :standalone_service do
      port 1237
    end
  end
end

class StandaloneClient

  def initialize base_url
    @base_url = base_url
  end

  def call
    uri = URI("#{@base_url}/something")
    post_req = Net::HTTP::Post.new(uri.path)
    post_req['Content-Type'] = "application/json"
    post_req.body = {a: "body"}.to_json
    response = Net::HTTP.start(uri.hostname, uri.port) do |http|
      http.request post_req
    end
    response.body
  end

end

describe StandaloneClient, pact: true do

  subject { StandaloneClient.new("http://localhost:1237") }

  describe "call" do

    let(:expected_body) { {a: "body"} }
    let(:response_body) { {a: 'response body'} }

    before do
      standalone_service.
        upon_receiving("a request to create something").with(method: 'post', path: '/something', body: expected_body).
        will_respond_with(status: 200, headers: {}, body: response_body)
    end

    it "will pass" do
      expect(subject.call).to eq response_body.to_json
    end
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
pact-1.4.0.rc4 spec/standalone/consumer_pass_test.rb
pact-1.4.0.rc3 spec/standalone/consumer_pass_test.rb
pact-1.4.0.rc2 spec/standalone/consumer_pass_test.rb
pact-1.3.3 spec/standalone/consumer_pass_test.rb
pact-1.3.2 spec/standalone/consumer_pass_test.rb
pact-1.3.1 spec/standalone/consumer_pass_test.rb
pact-1.3.0 spec/standalone/consumer_pass_test.rb
pact-1.2.1.rc2 spec/standalone/consumer_pass_test.rb
pact-1.2.1.rc1 spec/standalone/consumer_pass_test.rb
pact-1.1.1 spec/standalone/consumer_pass_test.rb