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
3mix-castronaut-0.5.0.2 vendor/rack/test/spec_rack_builder.rb
masover-castronaut-0.4.4.4 vendor/rack/test/spec_rack_builder.rb
masover-castronaut-0.4.4.5 vendor/rack/test/spec_rack_builder.rb
masover-castronaut-0.5.0.1 vendor/rack/test/spec_rack_builder.rb
relevance-castronaut-0.2.0 vendor/rack/test/spec_rack_builder.rb
relevance-castronaut-0.2.5 vendor/rack/test/spec_rack_builder.rb
relevance-castronaut-0.3.0 vendor/rack/test/spec_rack_builder.rb
relevance-castronaut-0.3.5 vendor/rack/test/spec_rack_builder.rb
relevance-castronaut-0.3.6 vendor/rack/test/spec_rack_builder.rb
relevance-castronaut-0.4.1 vendor/rack/test/spec_rack_builder.rb
relevance-castronaut-0.4.2 vendor/rack/test/spec_rack_builder.rb
relevance-castronaut-0.4.3 vendor/rack/test/spec_rack_builder.rb
relevance-castronaut-0.4.4 vendor/rack/test/spec_rack_builder.rb
relevance-castronaut-0.4.5 vendor/rack/test/spec_rack_builder.rb
relevance-castronaut-0.4.6 vendor/rack/test/spec_rack_builder.rb
relevance-castronaut-0.5.0 vendor/rack/test/spec_rack_builder.rb
relevance-castronaut-0.5.1 vendor/rack/test/spec_rack_builder.rb
relevance-castronaut-0.5.2 vendor/rack/test/spec_rack_builder.rb
relevance-castronaut-0.5.3 vendor/rack/test/spec_rack_builder.rb
relevance-castronaut-0.5.4 vendor/rack/test/spec_rack_builder.rb