Sha256: 7289b7f211b817ee7cdbeaaa345a1b41352d943e57fccc70b40c9e8b78796444

Contents?: true

Size: 1.01 KB

Versions: 11

Compression:

Stored size: 1.01 KB

Contents

require 'spec_helper'

describe Grape::Middleware::Prefixer do
  let(:app){ lambda{|env| [200, {}, env['PATH_INFO']]} }
  subject{ Grape::Middleware::Prefixer.new(app, @options || {}) }

  it 'should lop off a prefix (without a slash)' do
    @options = {:prefix => 'monkey'}
    subject.call('PATH_INFO' => '/monkey/beeswax').last.should == '/beeswax'
  end
  
  it 'should lop off a prefix (with a slash)' do
    @options = {:prefix => '/banana'}
    subject.call('PATH_INFO' => '/banana/peel').last.should == '/peel'
  end
  
  it 'should not lop off non-prefixes' do
    @options = {:prefix => '/monkey'}
    subject.call('PATH_INFO' => '/banana/peel').last.should == '/banana/peel'
  end
  
  it 'should pass through unaltered if there is no prefix' do
    subject.call('PATH_INFO' => '/awesome').last.should == '/awesome'
  end
  
  it 'should only remove the first instance of the prefix' do
    @options = {:prefix => 'api'}
    subject.call('PATH_INFO' => '/api/v1/api/awesome').last.should == '/v1/api/awesome'
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
grape-0.2.1.1 spec/grape/middleware/prefixer_spec.rb
grape-0.2.3 spec/grape/middleware/prefixer_spec.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/grape-0.2.2/spec/grape/middleware/prefixer_spec.rb
grape-0.2.2 spec/grape/middleware/prefixer_spec.rb
grape-0.2.1 spec/grape/middleware/prefixer_spec.rb
grape-0.2.0 spec/grape/middleware/prefixer_spec.rb
grape-0.1.5 spec/grape/middleware/prefixer_spec.rb
grape-0.1.4 spec/grape/middleware/prefixer_spec.rb
grape-0.1.3 spec/grape/middleware/prefixer_spec.rb
grape-0.1.1 spec/grape/middleware/prefixer_spec.rb
grape-0.1.0 spec/grape/middleware/prefixer_spec.rb