Sha256: f8f527fae110e6e07fe62f4ba83561718b6e5d5d8f8dc679f0a59da3ee5a7357

Contents?: true

Size: 1.57 KB

Versions: 5

Compression:

Stored size: 1.57 KB

Contents

require 'pact_broker/api/resources/base_resource'

module PactBroker
  module Api
    module Resources
      describe BaseResource do
        let(:request) { double('request', uri: uri).as_null_object }
        let(:response) { double('response') }
        let(:uri) { URI('http://example.org/path?query') }

        subject { BaseResource.new(request, response) }

        its(:resource_url) { is_expected.to eq 'http://example.org/path' }

        describe "options" do
          subject { options "/"; last_response }

          it "returns a list of allowed methods" do
            expect(subject.headers['Access-Control-Allow-Methods']).to eq "GET, OPTIONS"
          end
        end
      end

      ALL_RESOURCES = ObjectSpace.each_object(::Class).select {|klass| klass < BaseResource }

      ALL_RESOURCES.each do | resource |
        describe resource do
          let(:request) { double('request', uri: URI("http://example.org")).as_null_object }
          let(:response) { double('response') }

          it "includes OPTIONS in the list of allowed_methods" do
            expect(resource.new(request, response).allowed_methods).to include "OPTIONS"
          end

          it "calls super in its constructor" do
            expect(PactBroker.configuration.before_resource).to receive(:call)
            resource.new(request, response)
          end

          it "calls super in finish_request" do
            expect(PactBroker.configuration.after_resource).to receive(:call)
            resource.new(request, response).finish_request
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pact_broker-2.45.0 spec/lib/pact_broker/api/resources/base_resource_spec.rb
pact_broker-2.44.0 spec/lib/pact_broker/api/resources/base_resource_spec.rb
pact_broker-2.43.0 spec/lib/pact_broker/api/resources/base_resource_spec.rb
pact_broker-2.42.0 spec/lib/pact_broker/api/resources/base_resource_spec.rb
pact_broker-2.41.0 spec/lib/pact_broker/api/resources/base_resource_spec.rb