Sha256: 8358794466c57ff8d2a329ad1b42ece79417e0c5ce1b70763b6412a7f4632a01

Contents?: true

Size: 1.72 KB

Versions: 21

Compression:

Stored size: 1.72 KB

Contents

require 'rack/pact_broker/request_target'

module Rack
  module PactBroker
    describe RequestTarget do
      let(:rack_env) do
        {
          'CONTENT_TYPE' => content_type,
          'HTTP_ACCEPT' => accept,
          'PATH_INFO' => path
        }
      end
      let(:content_type) { nil }
      let(:accept) { nil }
      let(:path) { '' }

      describe "#request_for_ui?" do
        let(:path) { "/" }

        subject { RequestTarget.request_for_ui?(rack_env) }

        context "when the Accept header includes text/html" do
          let(:accept) { "text/html" }

          it { is_expected.to be true }
        end

        context "when the request is for a web asset with an Accept header of */*" do
          let(:path) { "/blah/foo.woff" }
          let(:accept) { "*/*" }

          it { is_expected.to be true }
        end

        context "when the request is for a content type served by the API (HAL browser request)" do
          let(:accept) { "application/hal+json, application/json, */*; q=0.01" }

          it { is_expected.to be false }
        end

        context "when the request is not for a web asset and the Accept headers is */* (default Accept header from curl request)" do
          let(:accept) { "*/*" }

          it { is_expected.to be false }
        end

        context "when the request is not for a web asset and no Accept header is specified" do
          let(:accept) { nil }

          it { is_expected.to be false }
        end

        context "when the request ends in a web asset extension but has Accept application/hal+json" do
          let(:accept) { "application/hal+json" }
          let(:path) { "/blah/foo.woff" }

          it { is_expected.to be false }
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
pact_broker-2.58.0 spec/lib/rack/pact_broker/request_target_spec.rb
pact_broker-2.57.0 spec/lib/rack/pact_broker/request_target_spec.rb
pact_broker-2.56.1 spec/lib/rack/pact_broker/request_target_spec.rb
pact_broker-2.56.0 spec/lib/rack/pact_broker/request_target_spec.rb
pact_broker-2.55.0 spec/lib/rack/pact_broker/request_target_spec.rb
pact_broker-2.54.0 spec/lib/rack/pact_broker/request_target_spec.rb
pact_broker-2.53.0 spec/lib/rack/pact_broker/request_target_spec.rb
pact_broker-2.52.2 spec/lib/rack/pact_broker/request_target_spec.rb
pact_broker-2.52.1 spec/lib/rack/pact_broker/request_target_spec.rb
pact_broker-2.52.0 spec/lib/rack/pact_broker/request_target_spec.rb
pact_broker-2.51.0 spec/lib/rack/pact_broker/request_target_spec.rb
pact_broker-2.50.1 spec/lib/rack/pact_broker/request_target_spec.rb
pact_broker-2.50.0 spec/lib/rack/pact_broker/request_target_spec.rb
pact_broker-2.49.0 spec/lib/rack/pact_broker/request_target_spec.rb
pact_broker-2.48.0 spec/lib/rack/pact_broker/request_target_spec.rb
pact_broker-2.47.1 spec/lib/rack/pact_broker/request_target_spec.rb
pact_broker-2.47.0 spec/lib/rack/pact_broker/request_target_spec.rb
pact_broker-2.46.0 spec/lib/rack/pact_broker/request_target_spec.rb
pact_broker-2.45.0 spec/lib/rack/pact_broker/request_target_spec.rb
pact_broker-2.44.0 spec/lib/rack/pact_broker/request_target_spec.rb