Sha256: ed1ea0bac0ced792388ff49f2fbcc7af366b5824ec2933647c62b2b8075d49e4

Contents?: true

Size: 958 Bytes

Versions: 2

Compression:

Stored size: 958 Bytes

Contents

shared_context :middleware_test do

  include_context :rack_test

  let(:inner_app){
    proc{[200, {}, []]}
  }

  subject(:app) do
    described_class.new(inner_app)
  end

  def collect_middleware rack_app
    middleware = [rack_app]
    while rack_app = rack_app.instance_variable_get(:@app)
      middleware << rack_app
    end
    middleware
  end


  def find_middleware rack_app, clazz
    return rack_app if rack_app.is_a?(clazz)
    collect_middleware(rack_app).find{|middleware| middleware.is_a?(clazz)}
  end

  RSpec::Matchers.define :be_using do |expected, *args|
    match do |actual|
      !!find_middleware(actual, expected)
    end
  end

  def create_middleware
    Class.new do
      attr_reader :app, :arg
      def initialize app, arg=nil, &block
        @app, @arg = app, arg
        block.call if block
      end

      def call env
        @app.call env
      end
    end

  end

  let(:middleware) do
    create_middleware
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sitehub-0.4.2 spec/support/shared_contexts/middleware_context.rb
sitehub-0.4.1 spec/support/shared_contexts/middleware_context.rb