Sha256: 7c1ed2a97b216d63463d18d3638a15d2aad33cbde8841fc349e191683426aed6

Contents?: true

Size: 1.06 KB

Versions: 9

Compression:

Stored size: 1.06 KB

Contents

require 'rails_helper'

describe LHC::Request do

  let(:request_options) do
    [
      { url: 'http://www.local.ch/restaurants' },
      { url: 'http://www.local.ch' }
    ]
  end

  let(:stub_parallel_requests) do
    stub_request(:get, "http://www.local.ch/restaurants").to_return(status: 200, body: '1')
    stub_request(:get, "http://www.local.ch").to_return(status: 200, body: '2')
  end

  it 'does parallel requests if you provide an array of requests' do
    stub_parallel_requests
    responses = LHC.request(request_options)
    expect(responses[0].body).to eq '1'
    expect(responses[1].body).to eq '2'
  end

  context 'interceptors' do

    before(:each) do
      class TestInterceptor < LHC::Interceptor; end
      LHC.configure { |c| c.interceptors = [TestInterceptor] }
    end

    it 'calls interceptors also for parallel requests' do
      stub_parallel_requests
      @called = 0
      allow_any_instance_of(TestInterceptor)
        .to receive(:before_request) { @called += 1 }
      LHC.request(request_options)
      expect(@called).to eq 2
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
lhc-3.4.0 spec/request/parallel_requests_spec.rb
lhc-3.3.0 spec/request/parallel_requests_spec.rb
lhc-3.2.0 spec/request/parallel_requests_spec.rb
lhc-3.1.1 spec/request/parallel_requests_spec.rb
lhc-3.1.0 spec/request/parallel_requests_spec.rb
lhc-3.0.0 spec/request/parallel_requests_spec.rb
lhc-2.0.0 spec/request/parallel_requests_spec.rb
lhc-1.2.0 spec/request/parallel_requests_spec.rb
lhc-1.1.0 spec/request/parallel_requests_spec.rb