Sha256: 349e79f8169db08d4ac427cd081d25f458a5d79a97184923d33f5136b01bfe2b

Contents?: true

Size: 1.67 KB

Versions: 8

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

8 entries across 8 versions & 1 rubygems

Version Path
proxy_fetcher-0.17.0 spec/proxy_fetcher/proxy_spec.rb
proxy_fetcher-0.16.0 spec/proxy_fetcher/proxy_spec.rb
proxy_fetcher-0.15.1 spec/proxy_fetcher/proxy_spec.rb
proxy_fetcher-0.15.0 spec/proxy_fetcher/proxy_spec.rb
proxy_fetcher-0.14.0 spec/proxy_fetcher/proxy_spec.rb
proxy_fetcher-0.13.0 spec/proxy_fetcher/proxy_spec.rb
proxy_fetcher-0.12.0 spec/proxy_fetcher/proxy_spec.rb
proxy_fetcher-0.11.0 spec/proxy_fetcher/proxy_spec.rb