Sha256: 930141907c2e9010b6d87230e1a724f36d059cb92e9ad6a9441a2faaa84e3c08

Contents?: true

Size: 1.99 KB

Versions: 3

Compression:

Stored size: 1.99 KB

Contents

require 'spec_helper'
require 'ronin/web/middleware/directories'

require 'web/helpers/rack_app'
require 'web/helpers/root'

describe Web::Middleware::Directories do
  include Helpers::Web::RackApp

  before(:all) do
    self.app = Class.new(Sinatra::Base) do
      extend Helpers::Web::Root

      use Ronin::Web::Middleware::Directories do |dirs|
        dirs.map '/test', root_path('test1')
        dirs.map '/test/sub', root_path('test2')
        dirs.map '/test/overriden', root_path('test3')
        dirs.map '/', root_path
      end

      get '/test/overriden/*' do
        'should not receive this'
      end

      get '/test/other' do
        'other'
      end
    end
  end

  describe "index_names" do
    subject { Web::Middleware::Directories.index_names }

    it { should include('index.html') }
    it { should include('index.xhtml') }
    it { should include('index.htm') }
  end

  it "should map remote directories to local directories" do
    get '/test/test1.txt'

    last_response.should be_ok
    last_response.body.should == "test1\n"
  end

  it "should map remote directories to index files in local directories" do
    get '/test/'

    last_response.should be_ok
    last_response.body.should == "index1\n"
  end

  it "should pass the request to the app if no index file exists" do
    get '/test/sub/'

    last_response.should_not be_ok
  end

  it "should match the whole remote path" do
    get '/test/sub/test2.txt'

    last_response.should be_ok
    last_response.body.should == "test2\n"
  end

  it "should map local directories to the root directory" do
    get '/test1/test1.txt'

    last_response.should be_ok
    last_response.body.should == "test1\n"
  end

  it "should match requests before the app" do
    get '/test/overriden/test3.txt'

    last_response.should be_ok
    last_response.body.should == "test3\n"
  end

  it "should still route un-matched requests to the app" do
    get '/test/other'

    last_response.should be_ok
    last_response.body.should == 'other'
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ronin-web-0.3.0.rc1 spec/web/middleware/directories_spec.rb
ronin-web-0.3.0.pre2 spec/web/middleware/directories_spec.rb
ronin-web-0.3.0.pre1 spec/web/middleware/directories_spec.rb