Sha256: 32f720551ad168ede39ad30269186a49d8153bd1905f516a0b09d189f39f27fb

Contents?: true

Size: 1.73 KB

Versions: 22

Compression:

Stored size: 1.73 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 return 404 if empty" do
    Rack::MockRequest.new(Rack::Cascade.new([])).get('/').should.be.not_found
  end

  specify "should append new app" do
    cascade = Rack::Cascade.new([], [404, 403])
    Rack::MockRequest.new(cascade).get('/').should.be.not_found
    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

22 entries across 21 versions & 10 rubygems

Version Path
kjvarga-rack-1.0.0 test/spec_rack_cascade.rb
qoobaa-rack-1.0.0.1 test/spec_rack_cascade.rb
qoobaa-rack-1.0.2 test/spec_rack_cascade.rb
rack-1.1.6 test/spec_rack_cascade.rb
rack-1.1.5 test/spec_rack_cascade.rb
rack-1.1.4 test/spec_rack_cascade.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/rack-1.1.3/test/spec_rack_cascade.rb
rack-1.1.3 test/spec_rack_cascade.rb
vanity-1.7.1 vendor/ruby/1.9.1/gems/rack-1.1.2/test/spec_rack_cascade.rb
rack-1.1.2 test/spec_rack_cascade.rb
rack-1.1.1 test/spec_rack_cascade.rb
rack-1.1.1.pre test/spec_rack_cascade.rb
eac-rack-1.1.1 test/spec_rack_cascade.rb
akamai_bookmarklet-0.1.2 vendor/gems/ruby/1.8/gems/rack-1.1.0/test/spec_rack_cascade.rb
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.9.1/gems/rack-1.1.0/test/spec_rack_cascade.rb
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.8/gems/rack-1.1.0/test/spec_rack_cascade.rb
akamai_bookmarklet-0.1.1 vendor/gems/ruby/1.8/gems/rack-1.1.0/test/spec_rack_cascade.rb
akamai_bookmarklet-0.1.0 vendor/gems/ruby/1.8/gems/rack-1.1.0/test/spec_rack_cascade.rb
rack-1.1.0 test/spec_rack_cascade.rb
rango-0.0.6 vendor/rack/test/spec_rack_cascade.rb