Sha256: 65ca9799730288cacddd47f8fe18fdf7dad763729cc6b066c42fdd4cfcd4f6e4

Contents?: true

Size: 1.8 KB

Versions: 24

Compression:

Stored size: 1.8 KB

Contents

require 'spec_helper'
require 'pact_broker/api/resources/pacticipant'


module PactBroker::Api

  module Resources

    describe Pacticipant do

      describe "DELETE" do

        let(:pacticpant) { double("pacticpant") }

        before do
          allow(PactBroker::Services::PacticipantService).to receive(:delete)
          allow(PactBroker::Services::PacticipantService).to receive(:find_pacticipant_by_name).and_return(pacticpant)
        end

        subject { delete("/pacticipants/Some%20Service" ) }

        context "when the resource exists" do
          it "deletes the pacticpant by name" do
            expect(PactBroker::Services::PacticipantService).to receive(:delete).with("Some Service")
            subject
          end

          it "returns a 204 OK" do
            subject
            expect(last_response.status).to eq 204
          end
        end

        context "when the resource doesn't exist" do

          let(:pacticpant) { nil }

          it "returns a 404 Not Found" do
            subject
            expect(last_response.status).to eq 404
          end
        end

        context "when an error occurs" do
          before do
            allow(PactBroker::Services::PacticipantService).to receive(:delete).and_raise("An error")
          end

          let(:response_body) { JSON.parse(last_response.body, symbolize_names: true) }

          it "returns a 500 Internal Server Error" do
            subject
            expect(last_response.status).to eq 500
          end

          it "returns an error message" do
            subject
            expect(response_body[:message]).to eq "An error"
          end

          it "returns the backtrace" do
            subject
            expect(response_body[:backtrace]).to be_instance_of(Array)
          end
        end
      end

    end
  end

end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
pact_broker-1.15.0 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-1.14.0 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-1.13.0 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-1.12.0 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-1.11.2 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-1.11.1 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-1.11.0 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-1.10.0 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-1.9.3 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-1.9.2 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-1.9.1 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-1.9.0 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-1.9.0.rc1 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-1.8.1 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-1.8.0 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-1.7.0 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-1.6.0 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-1.5.0 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-1.4.0 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-1.3.2.rc1 spec/lib/pact_broker/api/resources/pacticipant_spec.rb