Sha256: 3337e6030ff98981168ea0f4c642b53587d16931b8814d8b0e8301a9f9c17f3c

Contents?: true

Size: 1.98 KB

Versions: 33

Compression:

Stored size: 1.98 KB

Contents

require 'spec_helper'
require 'pact/consumer/mock_service_interaction_expectation'

describe Pact::Consumer::MockServiceInteractionExpectation do
  describe "as_json" do
    let(:options ) { {} }
    let(:request_as_json) { {a: 'request'} }
    let(:request) { instance_double('Pact::Request::Expected', :as_json => request_as_json, :options => options)}
    let(:response) { double('response') }
    let(:generated_response ) { double('generated_response', :to_json => 'generated_response') }
    let(:interaction) { instance_double('Pact::Interaction', :description => 'description', :request => request, :response => response, :provider_state => 'some state') }
    subject { described_class.new(interaction)}
    let(:expected_hash) { {:response => generated_response, :request => as_json_with_options, :description => '' } }

    before do
      Pact::Reification.stub(:from_term).with(response).and_return(generated_response)
    end

    it "generates an actual response" do
      Pact::Reification.should_receive(:from_term).with(response).and_return(generated_response)
      expect(subject.as_json[:response]).to eq generated_response
    end

    it "includes the options in the request" do
      expect(subject.as_json[:request]).to eq request_as_json
    end

    it "includes the provider state" do
      expect(subject.as_json[:provider_state]).to eq 'some state'
    end

    it "includes the description" do
      expect(subject.as_json[:description]).to eq 'description'
    end

    it "doesn't have any other keys" do
      expect(subject.as_json.keys).to eq [:description, :provider_state, :request, :response]
    end

    context "without options" do
      it "does not include the options key" do
        expect(subject.as_json.key?(:options)).to be_false
      end
    end

    context "with options" do
      let(:options) { {:opts => 'blah'} }
      it "includes the options in the request hash" do
        expect(subject.as_json[:request][:options]).to eq options
      end
    end
  end
   
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
pact-1.1.0 spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb
pact-1.1.0.rc5 spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb
pact-1.1.0.rc4 spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb
pact-1.1.0.rc3 spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb
pact-1.0.39 spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb
pact-1.1.0.rc2 spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb
pact-1.0.38 spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb
pact-1.1.0.rc1 spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb
pact-1.0.37 spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb
pact-1.0.36 spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb
pact-1.0.35 spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb
pact-1.0.34 spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb
pact-1.0.33 spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb
pact-1.0.32 spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb
pact-1.0.31 spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb
pact-1.0.30 spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb
pact-1.0.29 spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb
pact-1.0.28 spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb
pact-1.0.27 spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb
pact-1.0.26 spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb