Sha256: 446f6505d94bea8ea289fb2ac5aba9cb3c92643081cf877524d5ea61ac6e562d

Contents?: true

Size: 1.77 KB

Versions: 23

Compression:

Stored size: 1.77 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::Pacticipants::Service).to receive(:delete)
          allow(PactBroker::Pacticipants::Service).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::Pacticipants::Service).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::Pacticipants::Service).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

23 entries across 23 versions & 1 rubygems

Version Path
pact_broker-2.22.0 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-2.21.0 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-2.20.0 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-2.19.2 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-2.19.1 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-2.19.0 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-2.18.0 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-2.17.1 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-2.17.0 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-2.16.1 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-2.16.0 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-2.15.0 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-2.14.0 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-2.13.1 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-2.13.0 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-2.12.0 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-2.11.0 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-2.10.0 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-2.9.0 spec/lib/pact_broker/api/resources/pacticipant_spec.rb
pact_broker-2.9.0.beta.5 spec/lib/pact_broker/api/resources/pacticipant_spec.rb