Sha256: 62b29bf09bcd141c9f09d3fbee4d584d99361b6208007478a0b3e5f65d3cfaf3

Contents?: true

Size: 1.88 KB

Versions: 2

Compression:

Stored size: 1.88 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe ProxyFetcher::Proxy do
  before :all do
    ProxyFetcher.config.provider = :proxy_docker
  end

  before do
    @manager = ProxyFetcher::Manager.new
  end

  let(:proxy) { @manager.proxies.first.dup }

  it 'can initialize a new proxy object' do
    proxy = described_class.new(addr: '192.169.1.1', port: 8080, type: 'HTTP')

    expect(proxy).not_to be_nil
    expect(proxy.addr).to eq('192.169.1.1')
    expect(proxy.port).to eq(8080)
    expect(proxy.type).to eq('HTTP')
  end

  it 'checks schema' do
    proxy.type = ProxyFetcher::Proxy::HTTP
    expect(proxy.http?).to be_truthy
    expect(proxy.https?).to be_falsey
    expect(proxy.ssl?).to be_falsey

    proxy.type = ProxyFetcher::Proxy::HTTPS
    expect(proxy.https?).to be_truthy
    expect(proxy.http?).to be_truthy
    expect(proxy.ssl?).to be_truthy

    proxy.type = ProxyFetcher::Proxy::SOCKS4
    expect(proxy.socks4?).to be_truthy
    expect(proxy.ssl?).to be_truthy

    proxy.type = ProxyFetcher::Proxy::SOCKS5
    expect(proxy.socks5?).to be_truthy
    expect(proxy.ssl?).to be_truthy
  end

  it 'not connectable if IP addr is wrong' do
    proxy.addr = '192.168.1.0'
    expect(proxy.connectable?).to be_falsey
  end

  it 'not connectable if there are some error during connection request' do
    allow_any_instance_of(Net::HTTP).to receive(:start).and_raise(Errno::ECONNABORTED)
    expect(proxy.connectable?).to be_falsey
  end

  it "not connectable if server doesn't respond to head" do
    allow_any_instance_of(Net::HTTP).to receive(:start).and_return(false)
    expect(proxy.connectable?).to be_falsey
    expect(proxy.valid?).to be_falsey
  end

  it 'returns URI::Generic' do
    expect(proxy.uri).to be_a(URI::Generic)

    expect(proxy.uri.host).not_to be_empty
    expect(proxy.uri.port).not_to be_nil
  end

  it 'returns URL' do
    expect(proxy.url).to be_a(String)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
proxy_fetcher-0.6.4 spec/proxy_fetcher/proxy_spec.rb
proxy_fetcher-0.6.3 spec/proxy_fetcher/proxy_spec.rb