em-twitter 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.md +2 -2
- data/README.md +6 -4
- data/em-twitter.gemspec +21 -24
- data/lib/em-twitter/decoders/gzip_decoder.rb +1 -1
- data/lib/em-twitter/proxy.rb +1 -1
- data/lib/em-twitter/reconnectors/application_failure.rb +1 -1
- data/lib/em-twitter/reconnectors/network_failure.rb +1 -1
- data/lib/em-twitter/request.rb +6 -2
- data/lib/em-twitter/response.rb +1 -1
- data/lib/em-twitter/version.rb +1 -1
- data/lib/em_twitter.rb +1 -1
- data/spec/em-twitter/client_spec.rb +11 -11
- data/spec/em-twitter/connection_error_handling_spec.rb +1 -1
- data/spec/em-twitter/connection_reconnect_spec.rb +31 -31
- data/spec/em-twitter/connection_spec.rb +36 -36
- data/spec/em-twitter/decoders/base_decoder_spec.rb +4 -4
- data/spec/em-twitter/decoders/gzip_decoder_spec.rb +4 -4
- data/spec/em-twitter/proxy_spec.rb +11 -11
- data/spec/em-twitter/reconnectors/application_failure_spec.rb +26 -26
- data/spec/em-twitter/reconnectors/network_failure_spec.rb +28 -28
- data/spec/em-twitter/request_spec.rb +58 -38
- data/spec/em-twitter/response_spec.rb +45 -45
- data/spec/em_twitter_spec.rb +10 -7
- data/spec/spec_helper.rb +8 -2
- metadata +16 -130
- data/.gemtest +0 -0
- data/.gitignore +0 -40
- data/.rspec +0 -3
- data/.travis.yml +0 -7
- data/Gemfile +0 -7
- data/Guardfile +0 -6
- data/examples/stream.rb +0 -61
data/LICENSE.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2011 Steve Agalloco
|
1
|
+
Copyright (c) 2011-2013 Steve Agalloco
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
a copy of this software and associated documentation files (the
|
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
17
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
18
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
19
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
# EM-Twitter
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/em-twitter.png)][gem]
|
2
3
|
[![Build Status](https://secure.travis-ci.org/spagalloco/em-twitter.png?branch=master)][travis]
|
3
4
|
[![Dependency Status](https://gemnasium.com/spagalloco/em-twitter.png?travis)][gemnasium]
|
4
|
-
[![Code Climate](https://codeclimate.com/
|
5
|
-
|
6
|
-
EM-Twitter is an EventMachine-based ruby client for the [Twitter Streaming API](https://dev.twitter.com/docs/streaming-api).
|
5
|
+
[![Code Climate](https://codeclimate.com/github/spagalloco/em-twitter.png)][codeclimate]
|
7
6
|
|
7
|
+
[gem]: https://rubygems.org/gems/em-twitter
|
8
8
|
[travis]: http://travis-ci.org/spagalloco/em-twitter
|
9
9
|
[gemnasium]: https://gemnasium.com/spagalloco/em-twitter
|
10
10
|
[codeclimate]: https://codeclimate.com/github/spagalloco/em-twitter
|
11
11
|
|
12
|
+
EM-Twitter is an EventMachine-based ruby client for the [Twitter Streaming API](https://dev.twitter.com/docs/streaming-api).
|
13
|
+
|
12
14
|
## Usage
|
13
15
|
|
14
16
|
```ruby
|
@@ -127,4 +129,4 @@ Testing with EM can be a challenge, but was made incredibly easy through the use
|
|
127
129
|
|
128
130
|
## Copyright
|
129
131
|
|
130
|
-
Copyright (c)
|
132
|
+
Copyright (c) 2011-2013 Steve Agalloco. See [LICENSE](LICENSE.md) for details.
|
data/em-twitter.gemspec
CHANGED
@@ -1,31 +1,28 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'em-twitter/version'
|
3
5
|
|
4
|
-
Gem::Specification.new do |
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'em-twitter'
|
8
|
+
spec.version = EventMachine::Twitter::VERSION
|
9
|
+
spec.homepage = 'https://github.com/spagalloco/em-twitter'
|
10
|
+
spec.licenses = ['MIT']
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
spec.authors = ["Steve Agalloco"]
|
13
|
+
spec.email = ['steve.agalloco@gmail.com']
|
14
|
+
spec.description = %q{Twitter Streaming API client for EventMachine}
|
15
|
+
spec.summary = spec.description
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
spec.add_dependency 'eventmachine', '~> 1.0'
|
18
|
+
spec.add_dependency 'http_parser.rb', '~> 0.5'
|
19
|
+
spec.add_dependency 'simple_oauth', '~> 0.1'
|
17
20
|
|
18
|
-
|
19
|
-
gem.add_development_dependency 'rdiscount'
|
20
|
-
gem.add_development_dependency 'rspec', '>= 2.11'
|
21
|
-
gem.add_development_dependency 'simplecov'
|
22
|
-
gem.add_development_dependency 'yard'
|
23
|
-
gem.add_development_dependency 'mockingbird', '>= 0.2'
|
24
|
-
gem.add_development_dependency 'guard-rspec'
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.0'
|
25
22
|
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
spec.files = %w(.yardopts CONTRIBUTING.md LICENSE.md README.md Rakefile em-twitter.gemspec)
|
24
|
+
spec.files += Dir.glob("lib/**/*.rb")
|
25
|
+
spec.files += Dir.glob("spec/**/*")
|
29
26
|
|
30
|
-
|
27
|
+
spec.require_paths = ['lib']
|
31
28
|
end
|
data/lib/em-twitter/proxy.rb
CHANGED
data/lib/em-twitter/request.rb
CHANGED
@@ -96,7 +96,11 @@ module EventMachine
|
|
96
96
|
end
|
97
97
|
|
98
98
|
def oauth_header
|
99
|
-
|
99
|
+
if get?
|
100
|
+
SimpleOAuth::Header.new(@options[:method], full_uri, {}, @options[:oauth])
|
101
|
+
else
|
102
|
+
SimpleOAuth::Header.new(@options[:method], full_uri, params, @options[:oauth])
|
103
|
+
end
|
100
104
|
end
|
101
105
|
|
102
106
|
def basic_auth?
|
@@ -134,4 +138,4 @@ module EventMachine
|
|
134
138
|
|
135
139
|
end
|
136
140
|
end
|
137
|
-
end
|
141
|
+
end
|
data/lib/em-twitter/response.rb
CHANGED
data/lib/em-twitter/version.rb
CHANGED
data/lib/em_twitter.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require 'em-twitter'
|
1
|
+
require 'em-twitter'
|
@@ -2,23 +2,23 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe EM::Twitter::Client do
|
4
4
|
|
5
|
-
describe
|
6
|
-
it
|
5
|
+
describe "initialization" do
|
6
|
+
it "raises a ConfigurationError if both oauth and basic are used" do
|
7
7
|
opts = default_options.merge(:basic => { :username => 'Steve', :password => 'Agalloco' })
|
8
|
-
|
8
|
+
expect{
|
9
9
|
EM::Twitter::Client.new(opts)
|
10
|
-
}.
|
10
|
+
}.to raise_error(EM::Twitter::ConfigurationError)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
describe
|
14
|
+
describe ".connect" do
|
15
15
|
before do
|
16
16
|
conn = stub('EventMachine::Connection')
|
17
17
|
conn.stub(:start_tls).and_return(nil)
|
18
18
|
EM.stub(:connect).and_return(conn)
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
21
|
+
it "connects to the configured host/port" do
|
22
22
|
EventMachine.should_receive(:connect).with(
|
23
23
|
test_options[:host],
|
24
24
|
test_options[:port],
|
@@ -29,8 +29,8 @@ describe EM::Twitter::Client do
|
|
29
29
|
EM::Twitter::Client.connect(default_options)
|
30
30
|
end
|
31
31
|
|
32
|
-
context
|
33
|
-
it
|
32
|
+
context "when using a proxy" do
|
33
|
+
it "connects to the proxy server" do
|
34
34
|
EventMachine.should_receive(:connect).with(
|
35
35
|
"my-proxy",
|
36
36
|
8080,
|
@@ -50,11 +50,11 @@ describe EM::Twitter::Client do
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
describe
|
54
|
-
it
|
53
|
+
describe "#respond_to?" do
|
54
|
+
it "delegate to the connection" do
|
55
55
|
EM.run_block do
|
56
56
|
client = EM::Twitter::Client.connect(default_options)
|
57
|
-
client.respond_to?(:immediate_reconnect).
|
57
|
+
expect(client.respond_to?(:immediate_reconnect)).to be_true
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe "EM::Twitter::Connection error handling" do
|
4
4
|
error_callback_invoked('on_unauthorized', 401, 'Unauthorized')
|
5
5
|
error_callback_invoked('on_forbidden', 403, 'Forbidden')
|
6
6
|
error_callback_invoked('on_not_found', 404, 'Not Found')
|
@@ -2,10 +2,10 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
include EM::Twitter
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe "EM::Twitter::Connection reconnections" do
|
6
6
|
|
7
|
-
describe
|
8
|
-
context
|
7
|
+
describe "reconnector setting" do
|
8
|
+
context "on connect" do
|
9
9
|
before do
|
10
10
|
Mockingbird.setup(test_options) do
|
11
11
|
status 200, 'Success'
|
@@ -14,15 +14,15 @@ describe 'EM::Twitter::Connection reconnections' do
|
|
14
14
|
|
15
15
|
after { Mockingbird.teardown }
|
16
16
|
|
17
|
-
it
|
17
|
+
it "uses the network failure reconnector" do
|
18
18
|
EM.run_block do
|
19
19
|
client = Client.connect(default_options)
|
20
|
-
client.connection.reconnector.
|
20
|
+
expect(client.connection.reconnector).to be_kind_of(Reconnectors::NetworkFailure)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
context
|
25
|
+
context "after successful connect" do
|
26
26
|
before do
|
27
27
|
Mockingbird.setup(test_options) do
|
28
28
|
status 200, 'Success'
|
@@ -31,7 +31,7 @@ describe 'EM::Twitter::Connection reconnections' do
|
|
31
31
|
|
32
32
|
after { Mockingbird.teardown }
|
33
33
|
|
34
|
-
it
|
34
|
+
it "resets the network failure reconnector" do
|
35
35
|
Reconnectors::NetworkFailure.any_instance.should_receive(:reset)
|
36
36
|
EM.run do
|
37
37
|
EM::Timer.new(1) { EM.stop }
|
@@ -39,7 +39,7 @@ describe 'EM::Twitter::Connection reconnections' do
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
it
|
42
|
+
it "resets the application failure reconnector" do
|
43
43
|
Reconnectors::ApplicationFailure.any_instance.should_receive(:reset)
|
44
44
|
EM.run do
|
45
45
|
EM::Timer.new(1) { EM.stop }
|
@@ -49,7 +49,7 @@ describe 'EM::Twitter::Connection reconnections' do
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
context
|
52
|
+
context "on 4xx responses" do
|
53
53
|
before do
|
54
54
|
Mockingbird.setup(test_options) do
|
55
55
|
status 401, 'Unauthorized'
|
@@ -58,18 +58,18 @@ describe 'EM::Twitter::Connection reconnections' do
|
|
58
58
|
|
59
59
|
after { Mockingbird.teardown }
|
60
60
|
|
61
|
-
it
|
61
|
+
it "uses the application failure reconnector" do
|
62
62
|
EM.run do
|
63
63
|
client = Client.connect(default_options)
|
64
64
|
EM::Timer.new(1) do
|
65
|
-
client.connection.reconnector.
|
65
|
+
expect(client.connection.reconnector).to be_kind_of(Reconnectors::ApplicationFailure)
|
66
66
|
EM.stop
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
context
|
72
|
+
context "on reconnects" do
|
73
73
|
before do
|
74
74
|
Mockingbird.setup(test_options) do
|
75
75
|
on_connection(1) do
|
@@ -83,11 +83,11 @@ describe 'EM::Twitter::Connection reconnections' do
|
|
83
83
|
|
84
84
|
after { Mockingbird.teardown }
|
85
85
|
|
86
|
-
it
|
86
|
+
it "set the reconnector to the network failure reconnector" do
|
87
87
|
EM.run do
|
88
88
|
client = Client.connect(default_options)
|
89
89
|
EM::Timer.new(1) do
|
90
|
-
client.connection.reconnector.
|
90
|
+
expect(client.connection.reconnector).to be_kind_of(Reconnectors::NetworkFailure)
|
91
91
|
EM.stop
|
92
92
|
end
|
93
93
|
end
|
@@ -95,7 +95,7 @@ describe 'EM::Twitter::Connection reconnections' do
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
-
describe
|
98
|
+
describe "#reconnect" do
|
99
99
|
before do
|
100
100
|
Mockingbird.setup(test_options) do
|
101
101
|
on_connection(1) do
|
@@ -106,7 +106,7 @@ describe 'EM::Twitter::Connection reconnections' do
|
|
106
106
|
|
107
107
|
after { Mockingbird.teardown }
|
108
108
|
|
109
|
-
it
|
109
|
+
it "calls the on_reconnect callback on reconnects" do
|
110
110
|
called = false
|
111
111
|
|
112
112
|
EM.run do
|
@@ -114,10 +114,10 @@ describe 'EM::Twitter::Connection reconnections' do
|
|
114
114
|
client.on_reconnect { called = true; EM.stop }
|
115
115
|
end
|
116
116
|
|
117
|
-
called.
|
117
|
+
expect(called).to be_true
|
118
118
|
end
|
119
119
|
|
120
|
-
it
|
120
|
+
it "does not reconnect when auto_reconnect is false" do
|
121
121
|
EM.run do
|
122
122
|
client = Client.connect(default_options.merge(:auto_reconnect => false))
|
123
123
|
client.should_not_receive(:reconnect)
|
@@ -126,7 +126,7 @@ describe 'EM::Twitter::Connection reconnections' do
|
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
|
-
describe
|
129
|
+
describe "#immediate_reconnect" do
|
130
130
|
before do
|
131
131
|
Mockingbird.setup(test_options) do
|
132
132
|
100.times do
|
@@ -137,7 +137,7 @@ describe 'EM::Twitter::Connection reconnections' do
|
|
137
137
|
|
138
138
|
after { Mockingbird.teardown }
|
139
139
|
|
140
|
-
it
|
140
|
+
it "reconnects immediately" do
|
141
141
|
called = false
|
142
142
|
|
143
143
|
EM.run_block do
|
@@ -146,10 +146,10 @@ describe 'EM::Twitter::Connection reconnections' do
|
|
146
146
|
client.immediate_reconnect
|
147
147
|
end
|
148
148
|
|
149
|
-
called.
|
149
|
+
expect(called).to be_true
|
150
150
|
end
|
151
151
|
|
152
|
-
it
|
152
|
+
it "reconnects the current connection" do
|
153
153
|
EM.run_block do
|
154
154
|
client = Client.connect(default_options)
|
155
155
|
client.connection.should_receive(:reconnect).once
|
@@ -158,8 +158,8 @@ describe 'EM::Twitter::Connection reconnections' do
|
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
161
|
-
describe
|
162
|
-
context
|
161
|
+
describe "#on_max_reconnects" do
|
162
|
+
context "application failure" do
|
163
163
|
before do
|
164
164
|
Mockingbird.setup(test_options) do
|
165
165
|
status 200, "Success"
|
@@ -172,7 +172,7 @@ describe 'EM::Twitter::Connection reconnections' do
|
|
172
172
|
|
173
173
|
after { Mockingbird.teardown }
|
174
174
|
|
175
|
-
it "
|
175
|
+
it "notifies after reconnect limit is reached" do
|
176
176
|
timeout, retries = nil, nil
|
177
177
|
|
178
178
|
EM.run do
|
@@ -188,12 +188,12 @@ describe 'EM::Twitter::Connection reconnections' do
|
|
188
188
|
client.connection.reconnector = Reconnectors::ApplicationFailure.new(:reconnect_count => 320)
|
189
189
|
end
|
190
190
|
|
191
|
-
timeout.
|
192
|
-
retries.
|
191
|
+
expect(timeout).to eq(10)
|
192
|
+
expect(retries).to eq(320)
|
193
193
|
end
|
194
194
|
end
|
195
195
|
|
196
|
-
context
|
196
|
+
context "network failure" do
|
197
197
|
before do
|
198
198
|
Mockingbird.setup(test_options) do
|
199
199
|
status 200, "Success"
|
@@ -206,7 +206,7 @@ describe 'EM::Twitter::Connection reconnections' do
|
|
206
206
|
|
207
207
|
after { Mockingbird.teardown }
|
208
208
|
|
209
|
-
it "
|
209
|
+
it "notifies after reconnect limit is reached" do
|
210
210
|
timeout, retries = nil, nil
|
211
211
|
|
212
212
|
EM.run do
|
@@ -222,8 +222,8 @@ describe 'EM::Twitter::Connection reconnections' do
|
|
222
222
|
client.connection.reconnector = Reconnectors::NetworkFailure.new(:reconnect_count => 320)
|
223
223
|
end
|
224
224
|
|
225
|
-
timeout.
|
226
|
-
retries.
|
225
|
+
expect(timeout).to eq(0.25)
|
226
|
+
expect(retries).to eq(320)
|
227
227
|
end
|
228
228
|
end
|
229
229
|
end
|
@@ -2,18 +2,18 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe EM::Twitter::Connection do
|
4
4
|
|
5
|
-
describe
|
6
|
-
it
|
5
|
+
describe "#post_init" do
|
6
|
+
it "calls the on_inited callback" do
|
7
7
|
called = false
|
8
8
|
|
9
9
|
EM.run_block do
|
10
10
|
client = EM::Twitter::Client.connect(default_options.merge(:on_inited => lambda { called = true}))
|
11
11
|
end
|
12
12
|
|
13
|
-
called.
|
13
|
+
expect(called).to be_true
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
16
|
+
it "sets the inactivity timeout" do
|
17
17
|
EM.should_receive(:set_comm_inactivity_timeout)
|
18
18
|
EM.run_block do
|
19
19
|
client = EM::Twitter::Client.connect(default_options.merge(:timeout => 2))
|
@@ -21,8 +21,8 @@ describe EM::Twitter::Connection do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
describe
|
25
|
-
describe
|
24
|
+
describe "streaming" do
|
25
|
+
describe "#each with partial responses" do
|
26
26
|
before do
|
27
27
|
Mockingbird.setup(test_options) do
|
28
28
|
status '200', 'Success'
|
@@ -39,7 +39,7 @@ describe EM::Twitter::Connection do
|
|
39
39
|
|
40
40
|
after { Mockingbird.teardown }
|
41
41
|
|
42
|
-
it
|
42
|
+
it "converts response data into complete buffers" do
|
43
43
|
count = 0
|
44
44
|
|
45
45
|
EM.run do
|
@@ -55,11 +55,11 @@ describe EM::Twitter::Connection do
|
|
55
55
|
EM::Timer.new(10) { EM.stop }
|
56
56
|
end
|
57
57
|
|
58
|
-
count.
|
58
|
+
expect(count).to be >= 100
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
describe
|
62
|
+
describe "#each with full responses" do
|
63
63
|
before do
|
64
64
|
Mockingbird.setup(test_options) do
|
65
65
|
status '200', 'Success'
|
@@ -75,7 +75,7 @@ describe EM::Twitter::Connection do
|
|
75
75
|
|
76
76
|
after { Mockingbird.teardown }
|
77
77
|
|
78
|
-
it
|
78
|
+
it "emits each complete response chunk" do
|
79
79
|
responses = []
|
80
80
|
|
81
81
|
EM.run do
|
@@ -88,12 +88,12 @@ describe EM::Twitter::Connection do
|
|
88
88
|
EM::Timer.new(10) { EM.stop }
|
89
89
|
end
|
90
90
|
|
91
|
-
responses.size.
|
92
|
-
responses.last.
|
91
|
+
expect(responses.size).to be >= 100
|
92
|
+
expect(responses.last).to eq('{"foo":"bar"}')
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
describe
|
96
|
+
describe "stall handling" do
|
97
97
|
before do
|
98
98
|
stub_const("EM::Twitter::Connection::STALL_TIMEOUT", 5)
|
99
99
|
stub_const("EM::Twitter::Connection::STALL_TIMER", 1)
|
@@ -105,7 +105,7 @@ describe EM::Twitter::Connection do
|
|
105
105
|
|
106
106
|
after { Mockingbird.teardown }
|
107
107
|
|
108
|
-
it
|
108
|
+
it "invokes a no-data callback when stalled" do
|
109
109
|
called = false
|
110
110
|
EM.run do
|
111
111
|
client = EM::Twitter::Client.connect(default_options)
|
@@ -116,10 +116,10 @@ describe EM::Twitter::Connection do
|
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
|
-
called.
|
119
|
+
expect(called).to be_true
|
120
120
|
end
|
121
121
|
|
122
|
-
it
|
122
|
+
it "closes the connection when stalled to prompt a reconnect" do
|
123
123
|
called = false
|
124
124
|
EM.run do
|
125
125
|
client = EM::Twitter::Client.connect(default_options)
|
@@ -131,10 +131,10 @@ describe EM::Twitter::Connection do
|
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
|
-
called.
|
134
|
+
expect(called).to be_true
|
135
135
|
end
|
136
136
|
|
137
|
-
it
|
137
|
+
it "invokes a no-data callback when stalled without a response" do
|
138
138
|
stalled = false
|
139
139
|
EM.run do
|
140
140
|
client = EM::Twitter::Client.connect(default_options)
|
@@ -152,7 +152,7 @@ describe EM::Twitter::Connection do
|
|
152
152
|
end
|
153
153
|
end
|
154
154
|
|
155
|
-
stalled.
|
155
|
+
expect(stalled).to be_true
|
156
156
|
end
|
157
157
|
end
|
158
158
|
end
|
@@ -166,12 +166,12 @@ describe EM::Twitter::Connection do
|
|
166
166
|
client.on_close { called = true }
|
167
167
|
end
|
168
168
|
|
169
|
-
called.
|
169
|
+
expect(called).to be_true
|
170
170
|
end
|
171
171
|
end
|
172
172
|
|
173
|
-
describe
|
174
|
-
it
|
173
|
+
describe "#stop" do
|
174
|
+
it "closes the connection" do
|
175
175
|
EM.run_block do
|
176
176
|
client = EM::Twitter::Client.connect(default_options)
|
177
177
|
client.connection.should_receive(:close_connection).once
|
@@ -179,11 +179,11 @@ describe EM::Twitter::Connection do
|
|
179
179
|
end
|
180
180
|
end
|
181
181
|
|
182
|
-
it
|
182
|
+
it "gracefully closes" do
|
183
183
|
EM.run_block do
|
184
184
|
client = EM::Twitter::Client.connect(default_options)
|
185
185
|
client.stop
|
186
|
-
client.
|
186
|
+
expect(client).to be_gracefully_closed
|
187
187
|
end
|
188
188
|
end
|
189
189
|
|
@@ -191,12 +191,12 @@ describe EM::Twitter::Connection do
|
|
191
191
|
EM.run_block do
|
192
192
|
client = EM::Twitter::Client.connect(default_options)
|
193
193
|
client.stop
|
194
|
-
client.connection.auto_reconnect
|
194
|
+
expect(client.connection.auto_reconnect?).to be_false
|
195
195
|
end
|
196
196
|
end
|
197
197
|
end
|
198
198
|
|
199
|
-
describe
|
199
|
+
describe "#update" do
|
200
200
|
before do
|
201
201
|
Mockingbird.setup(test_options) do
|
202
202
|
100.times do
|
@@ -207,15 +207,15 @@ describe EM::Twitter::Connection do
|
|
207
207
|
|
208
208
|
after { Mockingbird.teardown }
|
209
209
|
|
210
|
-
it
|
210
|
+
it "updates the options hash" do
|
211
211
|
EM.run_block do
|
212
212
|
client = EM::Twitter::Client.connect(default_options)
|
213
213
|
client.connection.update(:params => { :track => 'rangers' })
|
214
|
-
client.connection.options[:params].
|
214
|
+
expect(client.connection.options[:params]).to eq({:track => 'rangers'})
|
215
215
|
end
|
216
216
|
end
|
217
217
|
|
218
|
-
it
|
218
|
+
it "reconnects after updating" do
|
219
219
|
EM.run_block do
|
220
220
|
client = EM::Twitter::Client.connect(default_options)
|
221
221
|
client.connection.should_receive(:immediate_reconnect).once
|
@@ -223,18 +223,18 @@ describe EM::Twitter::Connection do
|
|
223
223
|
end
|
224
224
|
end
|
225
225
|
|
226
|
-
it
|
226
|
+
it "uses the new options when reconnecting" do
|
227
227
|
EM.run_block do
|
228
228
|
client = EM::Twitter::Client.connect(default_options)
|
229
229
|
client.connection.should_receive(:send_data) do |request|
|
230
|
-
request.to_s.
|
230
|
+
expect(request.to_s).to include('track=rangers')
|
231
231
|
end
|
232
232
|
client.connection.update(:params => { :track => 'rangers' })
|
233
233
|
end
|
234
234
|
end
|
235
235
|
end
|
236
236
|
|
237
|
-
describe
|
237
|
+
describe "#auto_reconnect?" do
|
238
238
|
before do
|
239
239
|
Mockingbird.setup(test_options) do
|
240
240
|
100.times do
|
@@ -245,21 +245,21 @@ describe EM::Twitter::Connection do
|
|
245
245
|
|
246
246
|
after { Mockingbird.teardown }
|
247
247
|
|
248
|
-
it
|
248
|
+
it "indicates the auto_reconnect setting" do
|
249
249
|
EM.run do
|
250
250
|
client = EM::Twitter::Client.connect(default_options)
|
251
251
|
EM::Timer.new(1) do
|
252
|
-
client.auto_reconnect
|
252
|
+
expect(client.auto_reconnect?).to be_true
|
253
253
|
EM.stop
|
254
254
|
end
|
255
255
|
end
|
256
256
|
end
|
257
257
|
|
258
|
-
it
|
258
|
+
it "indicates the auto_reconnect setting when false" do
|
259
259
|
EM.run do
|
260
260
|
client = EM::Twitter::Client.connect(default_options.merge(:auto_reconnect => false))
|
261
261
|
EM::Timer.new(1) do
|
262
|
-
client.auto_reconnect
|
262
|
+
expect(client.auto_reconnect?).to be_false
|
263
263
|
EM.stop
|
264
264
|
end
|
265
265
|
end
|