Sha256: 0117d2fa03f2b718dc63e844a3bd4afea881224cf3d46a8127eecf244aac012f

Contents?: true

Size: 1.79 KB

Versions: 8

Compression:

Stored size: 1.79 KB

Contents

require 'spec_helper'

module Grape
  module DSL
    module MiddlewareSpec
      class Dummy
        include Grape::DSL::Middleware
      end
    end

    describe Middleware do
      subject { Class.new(MiddlewareSpec::Dummy) }
      let(:proc) { ->() {} }
      let(:foo_middleware) { Class.new }
      let(:bar_middleware) { Class.new }

      describe '.use' do
        it 'adds a middleware with the right operation' do
          expect(subject).to receive(:namespace_stackable).with(:middleware, [:use, foo_middleware, :arg1, proc])

          subject.use foo_middleware, :arg1, &proc
        end
      end

      describe '.insert' do
        it 'adds a middleware with the right operation' do
          expect(subject).to receive(:namespace_stackable).with(:middleware, [:insert, 0, :arg1, proc])

          subject.insert 0, :arg1, &proc
        end
      end

      describe '.insert_before' do
        it 'adds a middleware with the right operation' do
          expect(subject).to receive(:namespace_stackable).with(:middleware, [:insert_before, foo_middleware, :arg1, proc])

          subject.insert_before foo_middleware, :arg1, &proc
        end
      end

      describe '.insert_after' do
        it 'adds a middleware with the right operation' do
          expect(subject).to receive(:namespace_stackable).with(:middleware, [:insert_after, foo_middleware, :arg1, proc])

          subject.insert_after foo_middleware, :arg1, &proc
        end
      end

      describe '.middleware' do
        it 'returns the middleware stack' do
          subject.use foo_middleware, :arg1, &proc
          subject.insert_before bar_middleware, :arg1, :arg2

          expect(subject.middleware).to eq [[:use, foo_middleware, :arg1, proc], [:insert_before, bar_middleware, :arg1, :arg2]]
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.2.5/spec/grape/dsl/middleware_spec.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/grape-1.2.5/spec/grape/dsl/middleware_spec.rb
grape-1.2.5 spec/grape/dsl/middleware_spec.rb
grape-1.2.4 spec/grape/dsl/middleware_spec.rb
grape-1.2.3 spec/grape/dsl/middleware_spec.rb
grape-1.2.2 spec/grape/dsl/middleware_spec.rb
grape-1.2.1 spec/grape/dsl/middleware_spec.rb
grape-1.2.0 spec/grape/dsl/middleware_spec.rb