Sha256: 3bcc670863e6b4d2b5bc6444347972fd35f3d32b7e81669e4823f2469402f161

Contents?: true

Size: 1.6 KB

Versions: 14

Compression:

Stored size: 1.6 KB

Contents

require 'faraday'
require 'saddle'



### Make sure that multiple implementations of Saddle clients don't conflict with each other's middlewar.

describe Saddle::Client do

  context "multiple implementations" do
    context "using different middleware" do

      before :each do
        # Middlewares
        class Middleware1 < Faraday::Middleware
          # Hook for catching calls
          def subcall
          end

          def call(env)
            self.subcall
            @app.call(env)
          end
        end

        class Middleware2 < Faraday::Middleware
          # Hook for catching calls
          def subcall
          end

          def call(env)
            self.subcall
            @app.call(env)
          end
        end


        # Clients
        class Client1 < Saddle::Client
          add_middleware({:klass => Middleware1})
        end
        class Client2 < Saddle::Client
          add_middleware({:klass => Middleware2})
        end
      end

      it "should not overlap" do
        # Set up our stubs
        stubs = Faraday::Adapter::Test::Stubs.new do |stub|
          stub.get('/') {
            [
              200,
              {},
              'Party on!',
            ]
          }
        end

        # Set up our clients
        client1 = Client1.create(:stubs => stubs)
        client2 = Client2.create(:stubs => stubs)

        # Make sure client2's middleware isn't called
        Middleware1.any_instance.should_receive(:subcall)
        Middleware2.any_instance.should_not_receive(:subcall)

        # Make the call
        client1.requester.get('/')
      end

    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
saddle-0.0.31 spec/multiple_spec.rb
saddle-0.0.30 spec/multiple_spec.rb
saddle-0.0.27 spec/multiple_spec.rb
saddle-0.0.26 spec/multiple_spec.rb
saddle-0.0.25 spec/multiple_spec.rb
saddle-0.0.23 spec/multiple_spec.rb
saddle-0.0.22 spec/multiple_spec.rb
saddle-0.0.21 spec/multiple_spec.rb
saddle-0.0.19 spec/multiple_spec.rb
saddle-0.0.18 spec/multiple_spec.rb
saddle-0.0.17 spec/requester/multiple_spec.rb
saddle-0.0.16 spec/requester/multiple_spec.rb
saddle-0.0.15 spec/requester/multiple_spec.rb
saddle-0.0.14 spec/requester/multiple_spec.rb