Sha256: b205d0e854fe88c0e6fc2e3da565abe80e4840749e3c8330ec26093e0ff28ff0

Contents?: true

Size: 1.21 KB

Versions: 12

Compression:

Stored size: 1.21 KB

Contents

require "rack/pact_broker/use_when"
require "rack/test"

module Rack
  module PactBroker
    describe UseWhen do

      using Rack::PactBroker::UseWhen
      include Rack::Test::Methods

      class TestMiddleware
        def initialize(app, additional_headers)
          @app = app
          @additional_headers = additional_headers
        end

        def call(env)
          status, headers, body = @app.call(env)
          [status, headers.merge(@additional_headers), body]
        end
      end

      let(:app) do
        target_app = -> (_env) { [200, {}, []] }
        builder = Rack::Builder.new
        condition = ->(env) { env["PATH_INFO"] == "/match" }
        builder.use_when condition, TestMiddleware, { "Foo" => "Bar" }
        builder.run target_app
        builder.to_app
      end

      context "when the condition matches" do
        subject { get "/match" }

        it "uses the middleware" do
          expect(subject.headers).to include "Foo" => "Bar"
        end
      end

      context "when the condition does not match" do
        subject { get "/no-match" }

        it "does not use the middleware" do
          expect(subject.headers.keys).to_not include "Foo"
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
pact_broker-2.89.1 spec/lib/rack/pact_broker/use_when_spec.rb
pact_broker-2.89.0 spec/lib/rack/pact_broker/use_when_spec.rb
pact_broker-2.88.0 spec/lib/rack/pact_broker/use_when_spec.rb
pact_broker-2.87.0 spec/lib/rack/pact_broker/use_when_spec.rb
pact_broker-2.86.0 spec/lib/rack/pact_broker/use_when_spec.rb
pact_broker-2.85.1 spec/lib/rack/pact_broker/use_when_spec.rb
pact_broker-2.85.0 spec/lib/rack/pact_broker/use_when_spec.rb
pact_broker-2.84.0 spec/lib/rack/pact_broker/use_when_spec.rb
pact_broker-2.83.0 spec/lib/rack/pact_broker/use_when_spec.rb
pact_broker-2.82.0 spec/lib/rack/pact_broker/use_when_spec.rb
pact_broker-2.81.0 spec/lib/rack/pact_broker/use_when_spec.rb
pact_broker-2.80.0 spec/lib/rack/pact_broker/use_when_spec.rb