Sha256: cde8f05741995fbb6ab7252fffc77460d6e3e9d30668457ed10f97bde1904db3

Contents?: true

Size: 1.88 KB

Versions: 6

Compression:

Stored size: 1.88 KB

Contents

# encoding: utf-8
require 'spec_helper'

describe CapybaraProxy do
  context '#initialize' do
    it 'accepts no arguments' do
      expect {
        CapybaraProxy.new
      }.not_to raise_error
    end
  end

  context '#type=' do
    it 'sets the proxy type to none' do
      proxy = CapybaraProxy.new
      proxy.type = :none

      expect(proxy.type).to eq 'none'
    end

    it 'sets the proxy type to http' do
      proxy = CapybaraProxy.new
      proxy.type = :http

      expect(proxy.type).to eq 'http'
    end

    it 'sets the proxy type socks5' do
      proxy = CapybaraProxy.new
      proxy.type = :socks5

      expect(proxy.type).to eq 'socks5'
    end

    it 'raises an exception for invalid proxy type' do
      proxy = CapybaraProxy.new
      expect {
        proxy.type = :asdf
      }.to raise_error Exceptions::ProxyTypeInvalid
    end

    it 'results in an phantomjs argument' do
      proxy = CapybaraProxy.new
      proxy.host = 'host'
      proxy.port = 3128
      proxy.type = :socks5

      expect(proxy.as_phantomjs_arguments).to eq(
        [
          '--proxy=host:3128',
          '--proxy-type=socks5',
        ]
      )
    end
  end

  context '#as_phantomjs_arguments' do
    it 'accepts no arguments' do
      proxy = CapybaraProxy.new
      proxy.host = 'host'
      proxy.port = 3128

      proxy.user = double('user')
      allow(proxy.user).to receive(:to_login).with(cleartext: true).and_return('user:password')

      expect(proxy.as_phantomjs_arguments).to eq(
        [
          '--proxy=host:3128',
          '--proxy-auth=user:password',
        ]
      )
    end
  end

  context '#to_sym' do
    it 'accepts no arguments' do
      proxy = CapybaraProxy.new
      proxy.host = 'host'
      proxy.port = 3128

      proxy.user = double('user')
      allow(proxy.user).to receive(:name).and_return('user')

      expect(proxy.to_sym).to eq(:host_3128_user)
    end
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
proxy_tester-0.1.10 spec/capybara_proxy_spec.rb
proxy_tester-0.1.8 spec/capybara_proxy_spec.rb
proxy_tester-0.1.6 spec/capybara_proxy_spec.rb
proxy_tester-0.1.5 spec/capybara_proxy_spec.rb
proxy_tester-0.1.4 spec/capybara_proxy_spec.rb
proxy_tester-0.1.3 spec/capybara_proxy_spec.rb