/
connection_spec.rb
76 lines (55 loc) · 2.09 KB
/
connection_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
require 'helper'
describe Twitter::Streaming::Connection do
describe 'initialize' do
context 'no options provided' do
subject(:connection) { Twitter::Streaming::Connection.new }
it 'sets the default socket classes' do
expect(connection.tcp_socket_class).to eq TCPSocket
expect(connection.ssl_socket_class).to eq OpenSSL::SSL::SSLSocket
end
end
context 'custom socket classes provided in opts' do
class DummyTCPSocket; end
class DummySSLSocket; end
subject(:connection) do
Twitter::Streaming::Connection.new(tcp_socket_class: DummyTCPSocket, ssl_socket_class: DummySSLSocket)
end
it 'sets the default socket classes' do
expect(connection.tcp_socket_class).to eq DummyTCPSocket
expect(connection.ssl_socket_class).to eq DummySSLSocket
end
end
end
describe "connection" do
class DummyResponse
def initiailze(&block)
yield
end
def <<(data)
end
end
subject(:connection) do
Twitter::Streaming::Connection.new(tcp_socket_class: DummyTCPSocket, ssl_socket_class: DummySSLSocket)
end
let(:method) { :get }
let(:uri) { 'https://stream.twitter.com:443/1.1/statuses/sample.json' }
let(:ssl_socket) { double("ssl_socket") }
let(:request) { HTTP::Request.new(method, uri, {}) }
it 'requests via the proxy' do
expect(connection.ssl_socket_class).to receive(:new).and_return(ssl_socket)
allow(ssl_socket).to receive(:connect)
expect(connection).to receive(:new_tcp_socket).with('stream.twitter.com', 443)
connection.connect(request)
end
context "when using a proxy" do
let(:proxy) { {proxy_address: '127.0.0.1', proxy_port: 3328} }
let(:request) { HTTP::Request.new(method, uri, {}, proxy) }
it 'requests via the proxy' do
expect(connection.ssl_socket_class).to receive(:new).and_return(ssl_socket)
allow(ssl_socket).to receive(:connect)
expect(connection).to receive(:new_tcp_socket).with('127.0.0.1', 3328)
connection.connect(request)
end
end
end
end