Sha256: 01b53c83eeca42a0896cc4b39999486a305bee2ceff4a74dd4c092814cdaaab5

Contents?: true

Size: 1.67 KB

Versions: 7

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe ProxyFetcher::Proxy do
  let(:proxy) { described_class.new(addr: '192.169.1.1', port: 8080, type: 'HTTP') }

  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(HTTP::Client).to receive(:head).and_raise(HTTP::TimeoutError)
    expect(proxy.connectable?).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

  it 'returns URL with scheme' do
    expect(proxy.url(scheme: true)).to include('://')
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
proxy_fetcher-0.10.2 spec/proxy_fetcher/proxy_spec.rb
proxy_fetcher-0.10.1 spec/proxy_fetcher/proxy_spec.rb
proxy_fetcher-0.10.0 spec/proxy_fetcher/proxy_spec.rb
proxy_fetcher-0.9.0 spec/proxy_fetcher/proxy_spec.rb
proxy_fetcher-0.8.0 spec/proxy_fetcher/proxy_spec.rb
proxy_fetcher-0.7.1 spec/proxy_fetcher/proxy_spec.rb
proxy_fetcher-0.7.0 spec/proxy_fetcher/proxy_spec.rb