Sha256: 21d1775af40bacd223b0174ec959efb0a15427a1dfd26b926688ed0131841351

Contents?: true

Size: 1.06 KB

Versions: 27

Compression:

Stored size: 1.06 KB

Contents

require File.dirname(__FILE__) + '/helper'

class UpcaseMiddleware
  def initialize(app, *args, &block)
    @app = app
    @args = args
    @block = block
  end
  def call(env)
    env['PATH_INFO'] = env['PATH_INFO'].to_s.upcase
    @app.call(env)
  end
end

context "Middleware Pipelines" do

  setup do
    Sinatra.application = nil
    @app = Sinatra.application
  end

  teardown do
    Sinatra.application = nil
  end

  specify "should add middleware with use" do
    block = Proc.new { |env| }
    @app.use UpcaseMiddleware
    @app.use UpcaseMiddleware, "foo", "bar"
    @app.use UpcaseMiddleware, "foo", "bar", &block
    @app.send(:middleware).should.include([UpcaseMiddleware, [], nil])
    @app.send(:middleware).should.include([UpcaseMiddleware, ["foo", "bar"], nil])
    @app.send(:middleware).should.include([UpcaseMiddleware, ["foo", "bar"], block])
  end

  specify "should run middleware added with use" do
    get('/foo') { "FAIL!" }
    get('/FOO') { "PASS!" }
    use UpcaseMiddleware
    get_it '/foo'
    should.be.ok
    body.should.equal "PASS!"
  end

end

Version data entries

27 entries across 27 versions & 6 rubygems

Version Path
bmizerany-sinatra-0.9.1 compat/pipeline_test.rb
darkhelmet-sinatra-0.9.1.1 compat/pipeline_test.rb
darkhelmet-sinatra-0.9.1 compat/pipeline_test.rb
sinatra-sinatra-0.9.1.1 compat/pipeline_test.rb
sinatra-sinatra-0.9.1.2 compat/pipeline_test.rb
sinatra-sinatra-0.9.1.3 compat/pipeline_test.rb
sinatra-sinatra-0.9.1 compat/pipeline_test.rb
sinatra-sinatra-0.9.2 compat/pipeline_test.rb
sinatra-0.9.6 compat/pipeline_test.rb
sinatra-0.9.5 compat/pipeline_test.rb
akamai_bookmarklet-0.1.2 vendor/gems/ruby/1.8/gems/sinatra-0.9.4/compat/pipeline_test.rb
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.9.1/gems/sinatra-0.9.4/compat/pipeline_test.rb
akamai_bookmarklet-0.1.1 vendor/gems/ruby/1.8/gems/sinatra-0.9.4/compat/pipeline_test.rb
akamai_bookmarklet-0.1.0 vendor/gems/ruby/1.8/gems/sinatra-0.9.4/compat/pipeline_test.rb
middleman-0.12.2 lib/middleman/vendor/gems/gems/sinatra-0.9.4/compat/pipeline_test.rb
middleman-0.12.1 lib/middleman/vendor/gems/gems/sinatra-0.9.4/compat/pipeline_test.rb
middleman-0.12.0.pre3 lib/middleman/vendor/gems/gems/sinatra-0.9.4/compat/pipeline_test.rb
middleman-0.12.0.pre2 lib/middleman/vendor/gems/gems/sinatra-0.9.4/compat/pipeline_test.rb
middleman-0.12.0.pre lib/middleman/vendor/gems/gems/sinatra-0.9.4/compat/pipeline_test.rb
middleman-0.10.17 vendor/gems/gems/sinatra-0.9.4/compat/pipeline_test.rb