Sha256: aaa053a5f94db0f40f73ff29149136168c6fd33c83a3f6fdfbd31ae68e552260

Contents?: true

Size: 954 Bytes

Versions: 2

Compression:

Stored size: 954 Bytes

Contents

require 'spec_helper'

describe Grape::Middleware::Versioner do
  let(:app) { lambda{|env| [200, env, env['api.version']]} }
  subject { Grape::Middleware::Versioner.new(app, @options || {}) }
  
  it 'should set the API version based on the first path' do
    subject.call('PATH_INFO' => '/v1/awesome').last.should == 'v1'
  end
  
  it 'should cut the version out of the path' do
    subject.call('PATH_INFO' => '/v1/awesome')[1]['PATH_INFO'].should == '/awesome'
  end
  
  it 'should provide a nil version if no path is given' do
    subject.call('PATH_INFO' => '/').last.should be_nil
  end
  
  context 'with a pattern' do
    before{ @options = {:pattern => /v./i} }
    it 'should set the version if it matches' do
      subject.call('PATH_INFO' => '/v1/awesome').last.should == 'v1'
    end
    
    it 'should ignore the version if it fails to match' do
      subject.call('PATH_INFO' => '/awesome/radical').last.should be_nil
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
grape-0.0.0.alpha.2 spec/grape/middleware/versioner_spec.rb
grape-0.0.0.alpha.1 spec/grape/middleware/versioner_spec.rb