Sha256: 8b27a4d026185096971b6e28cc601105075168708dd19fd0c1d89f1b09987873
Contents?: true
Size: 1.88 KB
Versions: 9
Compression:
Stored size: 1.88 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 allow(Pact::Reification).to receive(:from_term).with(response).and_return(generated_response) end it "includes the response" do expect(subject.as_json[:response]).to eq 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
9 entries across 9 versions & 2 rubygems