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
relevance-castronaut-0.5.2 vendor/rack/test/spec_rack_cascade.rb
relevance-castronaut-0.5.3 vendor/rack/test/spec_rack_cascade.rb
relevance-castronaut-0.5.4 vendor/rack/test/spec_rack_cascade.rb
relevance-castronaut-0.6.0 vendor/rack/test/spec_rack_cascade.rb
relevance-castronaut-0.6.1 vendor/rack/test/spec_rack_cascade.rb
relevance-castronaut-0.7.4 vendor/rack/test/spec_rack_cascade.rb
relevance-castronaut-0.7.5 vendor/rack/test/spec_rack_cascade.rb
technomancy-rack-0.3.0 test/spec_rack_cascade.rb
timocratic-rack-1.0.0 test/spec_rack_cascade.rb
nbudin-castronaut-0.7.5 vendor/rack/test/spec_rack_cascade.rb
merb-core-1.1.3 spec10/public/webrat/test_app/gems/gems/rack-0.4.0/test/spec_rack_cascade.rb
merb-core-1.1.2 spec10/public/webrat/test_app/gems/gems/rack-0.4.0/test/spec_rack_cascade.rb
merb-core-1.1.1 spec10/public/webrat/test_app/gems/gems/rack-0.4.0/test/spec_rack_cascade.rb
merb-core-1.1.0 spec10/public/webrat/test_app/gems/gems/rack-0.4.0/test/spec_rack_cascade.rb
merb-core-1.1.0.rc1 spec10/public/webrat/test_app/gems/gems/rack-0.4.0/test/spec_rack_cascade.rb
middleman-0.12.2 lib/middleman/vendor/gems/gems/rack-1.0.1/test/spec_rack_cascade.rb
middleman-0.12.1 lib/middleman/vendor/gems/gems/rack-1.0.1/test/spec_rack_cascade.rb
middleman-0.12.0.pre3 lib/middleman/vendor/gems/gems/rack-1.0.1/test/spec_rack_cascade.rb
middleman-0.12.0.pre2 lib/middleman/vendor/gems/gems/rack-1.0.1/test/spec_rack_cascade.rb
middleman-0.12.0.pre lib/middleman/vendor/gems/gems/rack-1.0.1/test/spec_rack_cascade.rb