Sha256: dd89668182a5a0d9256174a7a243c1aae90e2b0f59e96342497ebb8ab384e174

Contents?: true

Size: 1.58 KB

Versions: 12

Compression:

Stored size: 1.58 KB

Contents

require 'spec_helper'

describe Grape::Middleware::Base do
  subject { Grape::Middleware::Base.new(blank_app) }  
  let(:blank_app) { lambda{|env| [200, {}, 'Hi there.']} }
  
  before do
    # Keep it one object for testing.
    subject.stub!(:dup).and_return(subject)
  end
  
  it 'should have the app as an accessor' do
    subject.app.should == blank_app
  end
  
  it 'should be able to access the request' do
    subject.call({})
    subject.request.should be_kind_of(Rack::Request)
  end
  
  it 'should call through to the app' do
    subject.call({}).should == [200, {}, 'Hi there.']
  end
  
  context 'callbacks' do
    it 'should call #before' do
      subject.should_receive(:before)
    end
  
    it 'should call #after' do
      subject.should_receive(:after)
    end
    
    after{ subject.call!({}) }
  end
  
  it 'should be able to access the response' do
    subject.call({})
    subject.response.should be_kind_of(Rack::Response)
  end
  
  context 'options' do
    it 'should persist options passed at initialization' do
      Grape::Middleware::Base.new(blank_app, {:abc => true}).options[:abc].should be_true
    end
    
    context 'defaults' do
      class ExampleWare < Grape::Middleware::Base
        def default_options
          {:monkey => true}
        end
      end
      
      it 'should persist the default options' do
        ExampleWare.new(blank_app).options[:monkey].should be_true
      end
      
      it 'should override default options when provided' do
        ExampleWare.new(blank_app, :monkey => false).options[:monkey].should be_false
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
grape-0.2.1.1 spec/grape/middleware/base_spec.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/grape-0.2.2/spec/grape/middleware/base_spec.rb
grape-0.2.2 spec/grape/middleware/base_spec.rb
grape-0.2.1 spec/grape/middleware/base_spec.rb
grape-0.2.0 spec/grape/middleware/base_spec.rb
grape-0.1.5 spec/grape/middleware/base_spec.rb
grape-0.1.4 spec/grape/middleware/base_spec.rb
grape-0.1.3 spec/grape/middleware/base_spec.rb
grape-0.1.1 spec/grape/middleware/base_spec.rb
grape-0.1.0 spec/grape/middleware/base_spec.rb
grape-0.0.0.alpha.2 spec/grape/middleware/base_spec.rb
grape-0.0.0.alpha.1 spec/grape/middleware/base_spec.rb