Sha256: a2684d01051f00f67cd3ebbc54b88bf231dc84ee19b4e259f324f01e2eaee22f

Contents?: true

Size: 1.45 KB

Versions: 4

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Acfs::Adapter::Typhoeus do
  let(:adapter) { described_class.new }

  before do
    stub_request(:any, 'http://example.org').to_return status: 200
  end

  it 'raises an error' do
    request1 = Acfs::Request.new 'http://example.org' do |_rsp|
      raise '404-1'
    end
    request2 = Acfs::Request.new 'http://example.org' do |_rsp|
      raise '404-2'
    end
    adapter.queue request1
    adapter.queue request2

    expect { adapter.start }.to raise_error(/404\-[12]/)
    expect { adapter.start }.to_not raise_error
  end

  it 'raises timeout' do
    stub_request(:any, 'http://example.org').to_timeout

    request = Acfs::Request.new 'http://example.org'
    adapter.queue request

    expect { adapter.run(request) }.to raise_error(::Acfs::TimeoutError) do |err|
      expect(err.message).to eq 'Timeout reached: GET http://example.org'
    end
  end

  it 'raises connection errors' do
    WebMock.allow_net_connect!

    request = Acfs::Request.new 'http://should-never-exists.example.org'
    adapter.queue request

    expect { adapter.run(request) }.to raise_error(::Acfs::RequestError) do |err|
      expect(err.message).to eq 'Couldn\'t resolve host name: GET http://should-never-exists.example.org'
    end
  end

  it 'passes arguments to typhoeus hydra' do
    value = {key: 1, key2: 2}

    expect(::Typhoeus::Hydra).to receive(:new).with(value)

    described_class.new(**value).send :hydra
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
acfs-1.5.1 spec/acfs/adapter/typhoeus_spec.rb
acfs-1.5.0 spec/acfs/adapter/typhoeus_spec.rb
acfs-1.4.0 spec/acfs/adapter/typhoeus_spec.rb
acfs-1.3.4 spec/acfs/adapter/typhoeus_spec.rb