require 'spec_helper' require 'pact/consumer/configuration' module Pact::Consumer::Configuration describe MockService do let(:world) { Pact::Consumer::World.new } before do Pact.clear_configuration allow(Pact::Consumer::AppManager.instance).to receive(:register_mock_service_for) allow(Pact).to receive(:consumer_world).and_return(world) end describe "configure_consumer_contract_builder" do let(:consumer_name) {'consumer'} subject { MockService.build :mock_service, consumer_name, provider_name do port 1234 standalone true verify true end } let(:provider_name) { 'Mock Provider' } let(:consumer_contract_builder) { instance_double('Pact::Consumer::ConsumerContractBuilder') } let(:url) { "http://localhost:1234" } it "adds a verification to the Pact configuration" do allow(Pact::Consumer::ConsumerContractBuilder).to receive(:new).and_return(consumer_contract_builder) subject.finalize expect(consumer_contract_builder).to receive(:verify) Pact.configuration.provider_verifications.first.call end context "when standalone" do it "does not register the app with the AppManager" do expect(Pact::Consumer::AppManager.instance).to_not receive(:register_mock_service_for) subject.finalize end end context "when not standalone" do subject { MockService.build :mock_service, consumer_name, provider_name do port 1234 standalone false verify true end } it "registers the app with the AppManager" do expect(Pact::Consumer::AppManager.instance).to receive(:register_mock_service_for).with(provider_name, url) subject.finalize end end end end end