Sha256: a322a003dcf831b68229a10a7c3ba25861e1c20de60e7dd3fcf50f2c5711967f
Contents?: true
Size: 1.21 KB
Versions: 34
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
34 entries across 34 versions & 1 rubygems