Sha256: f65963c7b9070af5fcef04baeab9a8d42be5cdd6251da2fc0f4a38a5c55e9861

Contents?: true

Size: 1.78 KB

Versions: 52

Compression:

Stored size: 1.78 KB

Contents

require 'test/spec'

require 'rack/cascade'
require 'rack/mock'

require 'rack/urlmap'
require 'rack/file'

context "Rack::Cascade" do
  docroot = File.expand_path(File.dirname(__FILE__))
  app1 = Rack::File.new(docroot)

  app2 = Rack::URLMap.new("/crash" => lambda { |env| raise "boom" })

  app3 = Rack::URLMap.new("/foo" => lambda { |env|
                            [200, { "Content-Type" => "text/plain"}, [""]]})

  specify "should dispatch onward on 404 by default" do
    cascade = Rack::Cascade.new([app1, app2, app3])
    Rack::MockRequest.new(cascade).get("/cgi/test").should.be.ok
    Rack::MockRequest.new(cascade).get("/foo").should.be.ok
    Rack::MockRequest.new(cascade).get("/toobad").should.be.not_found
    Rack::MockRequest.new(cascade).get("/cgi/../bla").should.be.forbidden
  end

  specify "should dispatch onward on whatever is passed" do
    cascade = Rack::Cascade.new([app1, app2, app3], [404, 403])
    Rack::MockRequest.new(cascade).get("/cgi/../bla").should.be.not_found
  end

  specify "should fail if empty" do
    lambda { Rack::MockRequest.new(Rack::Cascade.new([])).get("/") }.
      should.raise(ArgumentError)
  end

  specify "should append new app" do
    cascade = Rack::Cascade.new([], [404, 403])
    lambda { Rack::MockRequest.new(cascade).get('/cgi/test') }.
      should.raise(ArgumentError)
    cascade << app2
    Rack::MockRequest.new(cascade).get('/cgi/test').should.be.not_found
    Rack::MockRequest.new(cascade).get('/cgi/../bla').should.be.not_found
    cascade << app1
    Rack::MockRequest.new(cascade).get('/cgi/test').should.be.ok
    Rack::MockRequest.new(cascade).get('/cgi/../bla').should.be.forbidden
    Rack::MockRequest.new(cascade).get('/foo').should.be.not_found
    cascade << app3
    Rack::MockRequest.new(cascade).get('/foo').should.be.ok
  end
end

Version data entries

52 entries across 52 versions & 13 rubygems

Version Path
3mix-castronaut-0.5.0.2 vendor/rack/test/spec_rack_cascade.rb
kastner-rack-0.3.171 test/spec_rack_cascade.rb
kastner-rack-0.3.186 test/spec_rack_cascade.rb
masover-castronaut-0.4.4.4 vendor/rack/test/spec_rack_cascade.rb
masover-castronaut-0.4.4.5 vendor/rack/test/spec_rack_cascade.rb
masover-castronaut-0.5.0.1 vendor/rack/test/spec_rack_cascade.rb
p8-castronaut-0.6.1.1 vendor/rack/test/spec_rack_cascade.rb
relevance-castronaut-0.2.0 vendor/rack/test/spec_rack_cascade.rb
relevance-castronaut-0.2.5 vendor/rack/test/spec_rack_cascade.rb
relevance-castronaut-0.3.0 vendor/rack/test/spec_rack_cascade.rb
relevance-castronaut-0.3.5 vendor/rack/test/spec_rack_cascade.rb
relevance-castronaut-0.3.6 vendor/rack/test/spec_rack_cascade.rb
relevance-castronaut-0.4.1 vendor/rack/test/spec_rack_cascade.rb
relevance-castronaut-0.4.2 vendor/rack/test/spec_rack_cascade.rb
relevance-castronaut-0.4.3 vendor/rack/test/spec_rack_cascade.rb
relevance-castronaut-0.4.4 vendor/rack/test/spec_rack_cascade.rb
relevance-castronaut-0.4.5 vendor/rack/test/spec_rack_cascade.rb
relevance-castronaut-0.4.6 vendor/rack/test/spec_rack_cascade.rb
relevance-castronaut-0.5.0 vendor/rack/test/spec_rack_cascade.rb
relevance-castronaut-0.5.1 vendor/rack/test/spec_rack_cascade.rb