Sha256: 61d617eca9f4c5f5c2e8d17537e6a1baacfaf8d0c537afbaa2188374114a08aa

Contents?: true

Size: 1.37 KB

Versions: 30

Compression:

Stored size: 1.37 KB

Contents

require 'test/spec'

require 'rack/builder'
require 'rack/mock'

context "Rack::Builder" do
  specify "chains apps by default" do
    app = Rack::Builder.new do
      use Rack::ShowExceptions
      run lambda { |env| raise "bzzzt" }
    end.to_app

    Rack::MockRequest.new(app).get("/").should.be.server_error
    Rack::MockRequest.new(app).get("/").should.be.server_error
    Rack::MockRequest.new(app).get("/").should.be.server_error
  end

  specify "has implicit #to_app" do
    app = Rack::Builder.new do
      use Rack::ShowExceptions
      run lambda { |env| raise "bzzzt" }
    end

    Rack::MockRequest.new(app).get("/").should.be.server_error
    Rack::MockRequest.new(app).get("/").should.be.server_error
    Rack::MockRequest.new(app).get("/").should.be.server_error
  end

  specify "supports blocks on use" do
    app = Rack::Builder.new do
      use Rack::ShowExceptions
      use Rack::Auth::Basic do |username, password|
        'secret' == password
      end

      run lambda { |env| [200, {}, 'Hi Boss'] }
    end

    response = Rack::MockRequest.new(app).get("/")
    response.should.be.client_error
    response.status.should.equal 401

    # with auth...
    response = Rack::MockRequest.new(app).get("/", 
        'HTTP_AUTHORIZATION' => 'Basic ' + ["joe:secret"].pack("m*"))
    response.status.should.equal 200
    response.body.to_s.should.equal 'Hi Boss'
  end

end

Version data entries

30 entries across 30 versions & 7 rubygems

Version Path
technomancy-rack-0.3.0 test/spec_rack_builder.rb
merb-core-1.1.3 spec10/public/webrat/test_app/gems/gems/rack-0.4.0/test/spec_rack_builder.rb
merb-core-1.1.2 spec10/public/webrat/test_app/gems/gems/rack-0.4.0/test/spec_rack_builder.rb
merb-core-1.1.1 spec10/public/webrat/test_app/gems/gems/rack-0.4.0/test/spec_rack_builder.rb
merb-core-1.1.0 spec10/public/webrat/test_app/gems/gems/rack-0.4.0/test/spec_rack_builder.rb
merb-core-1.1.0.rc1 spec10/public/webrat/test_app/gems/gems/rack-0.4.0/test/spec_rack_builder.rb
merb-core-1.1.0.pre spec10/public/webrat/test_app/gems/gems/rack-0.4.0/test/spec_rack_builder.rb
rack-0.4.0 test/spec_rack_builder.rb
rack-0.3.0 test/spec_rack_builder.rb
sinatra-0.2.2 vendor/rack/test/spec_rack_builder.rb