em-twitter 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -2,14 +2,14 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe EM::Twitter::BaseDecoder do
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe "#decode" do
|
6
6
|
before do
|
7
7
|
@decoder = EM::Twitter::BaseDecoder.new
|
8
8
|
end
|
9
9
|
|
10
|
-
it
|
11
|
-
@decoder.decode('abc').
|
10
|
+
it "passes through the response data" do
|
11
|
+
expect(@decoder.decode('abc')).to eq('abc')
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
end
|
15
|
+
end
|
@@ -2,19 +2,19 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe EM::Twitter::GzipDecoder do
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe "#decode" do
|
6
6
|
before do
|
7
7
|
@decoder = EM::Twitter::GzipDecoder.new
|
8
8
|
end
|
9
9
|
|
10
|
-
it
|
10
|
+
it "decodes the response data" do
|
11
11
|
output = StringIO.new
|
12
12
|
gz = Zlib::GzipWriter.new(output)
|
13
13
|
gz.write('abc')
|
14
14
|
gz.close
|
15
15
|
|
16
|
-
@decoder.decode(output.string).
|
16
|
+
expect(@decoder.decode(output.string)).to eq('abc')
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
end
|
20
|
+
end
|
@@ -1,23 +1,23 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe EM::Twitter::Proxy do
|
4
|
-
describe
|
5
|
-
it
|
4
|
+
describe ".new" do
|
5
|
+
it "interprets a proxy configuration" do
|
6
6
|
proxy = EM::Twitter::Proxy.new(proxy_options[:proxy])
|
7
|
-
proxy.user.
|
8
|
-
proxy.password.
|
9
|
-
proxy.uri.
|
7
|
+
expect(proxy.user).to eq('username')
|
8
|
+
expect(proxy.password).to eq('password')
|
9
|
+
expect(proxy.uri).to eq('http://my-proxy:8080')
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
describe
|
14
|
-
it
|
15
|
-
EM::Twitter::Proxy.new.header.
|
13
|
+
describe "#header" do
|
14
|
+
it "returns false when no proxy credentials are passed" do
|
15
|
+
expect(EM::Twitter::Proxy.new.header).to be_false
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it "generates a header when passed credentials" do
|
19
19
|
proxy = EM::Twitter::Proxy.new(proxy_options[:proxy])
|
20
|
-
proxy.header.
|
20
|
+
expect(proxy.header).to be
|
21
21
|
end
|
22
22
|
end
|
23
|
-
end
|
23
|
+
end
|
@@ -3,40 +3,40 @@ require 'spec_helper'
|
|
3
3
|
include EM::Twitter::Reconnectors
|
4
4
|
|
5
5
|
describe EM::Twitter::Reconnectors::ApplicationFailure do
|
6
|
-
describe
|
7
|
-
it
|
6
|
+
describe "initialization" do
|
7
|
+
it "initializes the reconnect_timeout" do
|
8
8
|
reconn = ApplicationFailure.new
|
9
|
-
reconn.reconnect_timeout.
|
9
|
+
expect(reconn.reconnect_timeout).to eq(ApplicationFailure::START)
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
12
|
+
it "accepts an options hash" do
|
13
13
|
reconn = ApplicationFailure.new(:reconnect_count => 25)
|
14
|
-
reconn.reconnect_count.
|
14
|
+
expect(reconn.reconnect_count).to eq(25)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
describe
|
19
|
-
it
|
18
|
+
describe "reconnect_timeout" do
|
19
|
+
it "returns the reconnect_timeout" do
|
20
20
|
reconn = ApplicationFailure.new
|
21
21
|
reconn.reconnect_timeout = 12
|
22
|
-
reconn.reconnect_timeout.
|
22
|
+
expect(reconn.reconnect_timeout).to eq(12)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
describe
|
27
|
-
it
|
26
|
+
describe "#increment" do
|
27
|
+
it "increments the reconnect_count" do
|
28
28
|
reconn = ApplicationFailure.new
|
29
29
|
reconn.increment
|
30
|
-
reconn.reconnect_count.
|
30
|
+
expect(reconn.reconnect_count).to eq(1)
|
31
31
|
end
|
32
32
|
|
33
|
-
it
|
33
|
+
it "increments the reconnect_timeout" do
|
34
34
|
reconn = ApplicationFailure.new
|
35
35
|
reconn.increment
|
36
|
-
reconn.reconnect_timeout.
|
36
|
+
expect(reconn.reconnect_timeout).to eq(20)
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
39
|
+
it "accepts a block and yields the current timeout" do
|
40
40
|
recon_timeout = 0
|
41
41
|
|
42
42
|
reconn = ApplicationFailure.new
|
@@ -44,31 +44,31 @@ describe EM::Twitter::Reconnectors::ApplicationFailure do
|
|
44
44
|
recon_timeout = timeout
|
45
45
|
end
|
46
46
|
|
47
|
-
recon_timeout.
|
47
|
+
expect(recon_timeout).to eq(10)
|
48
48
|
end
|
49
49
|
|
50
|
-
it
|
51
|
-
|
50
|
+
it "raises an ReconnectLimitError after exceeding max reconnects" do
|
51
|
+
expect {
|
52
52
|
reconn = ApplicationFailure.new(:reconnect_count => 11)
|
53
53
|
reconn.increment
|
54
|
-
}.
|
54
|
+
}.to raise_error(EventMachine::Twitter::ReconnectLimitError)
|
55
55
|
end
|
56
56
|
|
57
|
-
it
|
58
|
-
|
57
|
+
it "raises an ReconnectLimitError after exceeding the reconnect time limit" do
|
58
|
+
expect {
|
59
59
|
reconn = ApplicationFailure.new(:reconnect_timeout => 321)
|
60
60
|
reconn.increment
|
61
|
-
}.
|
61
|
+
}.to raise_error(EventMachine::Twitter::ReconnectLimitError)
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
describe
|
66
|
-
it
|
65
|
+
describe "#reset" do
|
66
|
+
it "resets the reconnect_count" do
|
67
67
|
reconn = ApplicationFailure.new(:reconnect_count => 25)
|
68
|
-
reconn.reconnect_count.
|
68
|
+
expect(reconn.reconnect_count).to eq(25)
|
69
69
|
|
70
70
|
reconn.reset
|
71
|
-
reconn.reconnect_count.
|
71
|
+
expect(reconn.reconnect_count).to be_zero
|
72
72
|
end
|
73
73
|
end
|
74
|
-
end
|
74
|
+
end
|
@@ -3,46 +3,46 @@ require 'spec_helper'
|
|
3
3
|
include EM::Twitter::Reconnectors
|
4
4
|
|
5
5
|
describe EM::Twitter::Reconnectors::NetworkFailure do
|
6
|
-
describe
|
7
|
-
it
|
6
|
+
describe "initialization" do
|
7
|
+
it "initializes the reconnect_timeout" do
|
8
8
|
reconn = NetworkFailure.new
|
9
|
-
reconn.reconnect_timeout.
|
9
|
+
expect(reconn.reconnect_timeout).to eq(NetworkFailure::START)
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
12
|
+
it "accepts an options hash" do
|
13
13
|
reconn = NetworkFailure.new(:reconnect_count => 25)
|
14
|
-
reconn.reconnect_count.
|
14
|
+
expect(reconn.reconnect_count).to eq(25)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
describe
|
19
|
-
it
|
18
|
+
describe "reconnect_timeout" do
|
19
|
+
it "returns the reconnect_timeout" do
|
20
20
|
reconn = NetworkFailure.new
|
21
21
|
reconn.reconnect_timeout = 12
|
22
|
-
reconn.reconnect_timeout.
|
22
|
+
expect(reconn.reconnect_timeout).to eq(12)
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
25
|
+
it "returns the maximum timeout when greater than the max" do
|
26
26
|
reconn = NetworkFailure.new
|
27
27
|
reconn.reconnect_timeout = NetworkFailure::MAX_TIMEOUT + 2
|
28
|
-
reconn.reconnect_timeout.
|
28
|
+
expect(reconn.reconnect_timeout).to eq(NetworkFailure::MAX_TIMEOUT)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
describe
|
33
|
-
it
|
32
|
+
describe "#increment" do
|
33
|
+
it "increments the reconnect_count" do
|
34
34
|
reconn = NetworkFailure.new
|
35
35
|
reconn.increment
|
36
|
-
reconn.reconnect_count.
|
36
|
+
expect(reconn.reconnect_count).to eq(1)
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
39
|
+
it "increments the reconnect_timeout" do
|
40
40
|
reconn = NetworkFailure.new
|
41
41
|
reconn.increment
|
42
|
-
reconn.reconnect_timeout.
|
42
|
+
expect(reconn.reconnect_timeout).to eq(0.5)
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
45
|
+
it "accepts a block and yields the current timeout" do
|
46
46
|
recon_timeout = 0
|
47
47
|
|
48
48
|
reconn = NetworkFailure.new
|
@@ -50,31 +50,31 @@ describe EM::Twitter::Reconnectors::NetworkFailure do
|
|
50
50
|
recon_timeout = timeout
|
51
51
|
end
|
52
52
|
|
53
|
-
recon_timeout.
|
53
|
+
expect(recon_timeout).to eq(0.25)
|
54
54
|
end
|
55
55
|
|
56
|
-
it
|
57
|
-
|
56
|
+
it "raises an ReconnectLimitError after exceeding max reconnects" do
|
57
|
+
expect {
|
58
58
|
reconn = NetworkFailure.new(:reconnect_count => 11)
|
59
59
|
reconn.increment
|
60
|
-
}.
|
60
|
+
}.to raise_error(EventMachine::Twitter::ReconnectLimitError)
|
61
61
|
end
|
62
62
|
|
63
|
-
it
|
64
|
-
|
63
|
+
it "raises an ReconnectLimitError after exceeding the reconnect time limit" do
|
64
|
+
expect {
|
65
65
|
reconn = NetworkFailure.new(:reconnect_timeout => 321)
|
66
66
|
reconn.increment
|
67
|
-
}.
|
67
|
+
}.to raise_error(EventMachine::Twitter::ReconnectLimitError)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
describe
|
72
|
-
it
|
71
|
+
describe "#reset" do
|
72
|
+
it "resets the reconnect_count" do
|
73
73
|
reconn = NetworkFailure.new(:reconnect_count => 25)
|
74
|
-
reconn.reconnect_count.
|
74
|
+
expect(reconn.reconnect_count).to eq(25)
|
75
75
|
|
76
76
|
reconn.reset
|
77
|
-
reconn.reconnect_count.
|
77
|
+
expect(reconn.reconnect_count).to be_zero
|
78
78
|
end
|
79
79
|
end
|
80
|
-
end
|
80
|
+
end
|
@@ -1,102 +1,122 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe EM::Twitter::Request do
|
4
|
-
describe
|
5
|
-
it
|
4
|
+
describe ".new" do
|
5
|
+
it "assigns a proxy if one is set" do
|
6
6
|
req = EM::Twitter::Request.new(proxy_options)
|
7
|
-
req.proxy.
|
7
|
+
expect(req.proxy).to be
|
8
8
|
end
|
9
9
|
|
10
|
-
it
|
10
|
+
it "overrides defaults" do
|
11
11
|
req = EM::Twitter::Request.new(default_options)
|
12
|
-
req.options[:path].
|
12
|
+
expect(req.options[:path]).to eq('/1/statuses/filter.json')
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
describe '#
|
17
|
-
it '
|
16
|
+
describe '#oauth_header' do
|
17
|
+
it 'passes params on POST requests' do
|
18
|
+
options = default_options.merge(:method => 'POST', :host => 'stream.twitter.com', :port => 443)
|
19
|
+
req = EM::Twitter::Request.new(options)
|
20
|
+
SimpleOAuth::Header.should_receive(:new).
|
21
|
+
with('POST', "http://stream.twitter.com/1/statuses/filter.json", {"track"=>"nfl"}, kind_of(Hash))
|
22
|
+
|
23
|
+
req.send(:oauth_header)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'passes params on the querystring for GET requests' do
|
27
|
+
options = default_options.merge(:method => 'GET', :host => 'stream.twitter.com', :port => 443)
|
28
|
+
req = EM::Twitter::Request.new(options)
|
29
|
+
SimpleOAuth::Header.should_receive(:new).
|
30
|
+
with('GET', "http://stream.twitter.com/1/statuses/filter.json?track=nfl", {}, kind_of(Hash))
|
31
|
+
|
32
|
+
req.send(:oauth_header)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#proxy?" do
|
37
|
+
it "defaults to false" do
|
18
38
|
req = EM::Twitter::Request.new
|
19
|
-
req.proxy
|
39
|
+
expect(req.proxy?).to be_false
|
20
40
|
end
|
21
41
|
|
22
|
-
it
|
42
|
+
it "returns true when a proxy is set" do
|
23
43
|
req = EM::Twitter::Request.new(proxy_options)
|
24
|
-
req.proxy
|
44
|
+
expect(req.proxy?).to be_true
|
25
45
|
end
|
26
46
|
end
|
27
47
|
|
28
|
-
describe
|
29
|
-
context
|
48
|
+
describe "#to_s" do
|
49
|
+
context "without a proxy" do
|
30
50
|
before do
|
31
51
|
@request = EM::Twitter::Request.new(default_options)
|
32
52
|
end
|
33
53
|
|
34
|
-
it
|
35
|
-
@request.to_s.
|
54
|
+
it "requests the defined path" do
|
55
|
+
expect(@request.to_s).to include('/1/statuses/filter.json')
|
36
56
|
end
|
37
57
|
end
|
38
58
|
|
39
|
-
context
|
59
|
+
context "when using a proxy" do
|
40
60
|
before do
|
41
61
|
@request = EM::Twitter::Request.new(default_options.merge(proxy_options))
|
42
62
|
end
|
43
63
|
|
44
|
-
it
|
45
|
-
@request.to_s.
|
64
|
+
it "requests the full uri" do
|
65
|
+
expect(@request.to_s).to include("POST http://#{test_options[:host]}:#{test_options[:port]}/1/statuses/filter.json")
|
46
66
|
end
|
47
67
|
|
48
|
-
it
|
49
|
-
@request.to_s.
|
68
|
+
it "includes a Proxy header" do
|
69
|
+
expect(@request.to_s).to include('Proxy-Authorization: Basic ')
|
50
70
|
end
|
51
71
|
end
|
52
72
|
|
53
|
-
context
|
73
|
+
context "Basic Authentication" do
|
54
74
|
before do
|
55
75
|
@request = EM::Twitter::Request.new(basic_auth_options)
|
56
76
|
end
|
57
77
|
|
58
|
-
it
|
59
|
-
@request.to_s.
|
78
|
+
it "creates an authorization header" do
|
79
|
+
expect(@request.to_s).to include('Authorization: Basic')
|
60
80
|
end
|
61
81
|
end
|
62
82
|
|
63
|
-
context
|
83
|
+
context "gzip encoding" do
|
64
84
|
before do
|
65
85
|
@request = EM::Twitter::Request.new(default_options.merge(:encoding => 'gzip'))
|
66
86
|
end
|
67
87
|
|
68
|
-
it
|
69
|
-
@request.to_s.
|
88
|
+
it "sets a keep-alive header" do
|
89
|
+
expect(@request.to_s).to include('Connection: Keep-Alive')
|
70
90
|
end
|
71
91
|
|
72
|
-
it
|
73
|
-
@request.to_s.
|
92
|
+
it "sets the accept-enconding header" do
|
93
|
+
expect(@request.to_s).to include('Accept-Encoding: deflate, gzip')
|
74
94
|
end
|
75
95
|
end
|
76
96
|
|
77
|
-
it
|
97
|
+
it "adds a POST body" do
|
78
98
|
@request = EM::Twitter::Request.new(default_options)
|
79
|
-
@request.to_s.
|
99
|
+
expect(@request.to_s).to include('track=nfl')
|
80
100
|
end
|
81
101
|
|
82
|
-
it
|
102
|
+
it "adds query parameters" do
|
83
103
|
@request = EM::Twitter::Request.new(default_options.merge(:method => :get))
|
84
|
-
@request.to_s.
|
104
|
+
expect(@request.to_s).to include('/1/statuses/filter.json?track=nfl')
|
85
105
|
end
|
86
106
|
|
87
|
-
it
|
107
|
+
it "allows defining a custom user-agent" do
|
88
108
|
@request = EM::Twitter::Request.new(default_options.merge(:user_agent => 'EM::Twitter Test Suite'))
|
89
|
-
@request.to_s.
|
109
|
+
expect(@request.to_s).to include('User-Agent: EM::Twitter Test Suite')
|
90
110
|
end
|
91
111
|
|
92
|
-
it
|
112
|
+
it "adds an accept header" do
|
93
113
|
@request = EM::Twitter::Request.new(default_options)
|
94
|
-
@request.to_s.
|
114
|
+
expect(@request.to_s).to include('Accept: */*')
|
95
115
|
end
|
96
116
|
|
97
|
-
it
|
117
|
+
it "adds custom headers" do
|
98
118
|
@request = EM::Twitter::Request.new(default_options.merge(:headers => { 'foo' => 'bar'}))
|
99
|
-
@request.to_s.
|
119
|
+
expect(@request.to_s).to include('foo: bar')
|
100
120
|
end
|
101
121
|
end
|
102
|
-
end
|
122
|
+
end
|
@@ -2,114 +2,114 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe EM::Twitter::Response do
|
4
4
|
|
5
|
-
describe
|
6
|
-
it
|
7
|
-
EM::Twitter::Response.new.body.
|
5
|
+
describe ".new" do
|
6
|
+
it "initializes an empty body" do
|
7
|
+
expect(EM::Twitter::Response.new.body).to eq('')
|
8
8
|
end
|
9
9
|
|
10
|
-
it
|
11
|
-
EM::Twitter::Response.new('ohai').body.
|
10
|
+
it "initializes with a body parameter" do
|
11
|
+
expect(EM::Twitter::Response.new('ohai').body).to eq('ohai')
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
describe
|
16
|
-
it
|
15
|
+
describe "#concat" do
|
16
|
+
it "sets the body when empty" do
|
17
17
|
response = EM::Twitter::Response.new
|
18
18
|
response.concat('{ "status" : true }')
|
19
|
-
response.body.
|
19
|
+
expect(response.body).to eq('{ "status" : true }')
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
22
|
+
it "appends to an existing body" do
|
23
23
|
response = EM::Twitter::Response.new('{ "status" : true')
|
24
24
|
response.concat(', "enabled" : false }')
|
25
|
-
response.body.
|
25
|
+
expect(response.body).to eq('{ "status" : true, "enabled" : false }')
|
26
26
|
end
|
27
27
|
|
28
|
-
it
|
28
|
+
it "only appends when passed json" do
|
29
29
|
str = '{ "status" : true'
|
30
30
|
response = EM::Twitter::Response.new(str)
|
31
31
|
response.concat('ohai')
|
32
|
-
response.body.
|
32
|
+
expect(response.body).to eq(str)
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
35
|
+
it "passively fails on nil" do
|
36
36
|
response = EM::Twitter::Response.new
|
37
|
-
|
37
|
+
expect {
|
38
38
|
response.concat(nil)
|
39
|
-
}.
|
39
|
+
}.not_to raise_error
|
40
40
|
end
|
41
41
|
|
42
|
-
it
|
42
|
+
it "passively fails on empty strings" do
|
43
43
|
response = EM::Twitter::Response.new('ohai')
|
44
44
|
response.concat('')
|
45
|
-
response.body.
|
45
|
+
expect(response.body).to eq('ohai')
|
46
46
|
end
|
47
47
|
|
48
|
-
it
|
48
|
+
it "passively fails on blank strings" do
|
49
49
|
response = EM::Twitter::Response.new('ohai')
|
50
50
|
response.concat(' ')
|
51
|
-
response.body.
|
51
|
+
expect(response.body).to eq('ohai')
|
52
52
|
end
|
53
53
|
|
54
|
-
it
|
54
|
+
it "is aliased as <<" do
|
55
55
|
response = EM::Twitter::Response.new
|
56
56
|
response << '{ "status" : true }'
|
57
|
-
response.body.
|
57
|
+
expect(response.body).to eq('{ "status" : true }')
|
58
58
|
end
|
59
59
|
|
60
|
-
it
|
60
|
+
it "updates the timestamp when data is received" do
|
61
61
|
response = EM::Twitter::Response.new
|
62
62
|
response << '{ "status" : true }'
|
63
|
-
response.timestamp.
|
63
|
+
expect(response.timestamp).to be_kind_of(Time)
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
describe
|
68
|
-
it
|
69
|
-
EM::Twitter::Response.new('{ "status" : true').complete
|
67
|
+
describe "#complete?" do
|
68
|
+
it "returns false when an incomplete body" do
|
69
|
+
expect(EM::Twitter::Response.new('{ "status" : true').complete?).to be_false
|
70
70
|
end
|
71
71
|
|
72
|
-
it
|
73
|
-
EM::Twitter::Response.new('{ "status" : true }').complete
|
72
|
+
it "returns false when an complete body" do
|
73
|
+
expect(EM::Twitter::Response.new('{ "status" : true }').complete?).to be_true
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
describe
|
78
|
-
it
|
77
|
+
describe "#older_than?" do
|
78
|
+
it "returns false when the last response is younger than the number of seconds" do
|
79
79
|
response = EM::Twitter::Response.new
|
80
|
-
response.older_than?(100).
|
80
|
+
expect(response.older_than?(100)).to be_false
|
81
81
|
end
|
82
82
|
|
83
|
-
it
|
83
|
+
it "returns true when the last response is older than the number of seconds" do
|
84
84
|
response = EM::Twitter::Response.new
|
85
85
|
response.concat('fakebody')
|
86
86
|
sleep(2)
|
87
|
-
response.older_than?(1).
|
87
|
+
expect(response.older_than?(1)).to be_true
|
88
88
|
end
|
89
89
|
|
90
|
-
it
|
90
|
+
it "generates a timestamp when no initial timestamp exists" do
|
91
91
|
response = EM::Twitter::Response.new
|
92
92
|
response.older_than?(100)
|
93
|
-
response.timestamp.
|
93
|
+
expect(response.timestamp).to be_kind_of(Time)
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
|
-
describe
|
98
|
-
it
|
99
|
-
EM::Twitter::Response.new.
|
97
|
+
describe "#empty?" do
|
98
|
+
it "returns true when an empty body" do
|
99
|
+
expect(EM::Twitter::Response.new).to be_empty
|
100
100
|
end
|
101
101
|
|
102
|
-
it
|
103
|
-
EM::Twitter::Response.new('{ "status" : true }').
|
102
|
+
it "returns false when a body is present" do
|
103
|
+
expect(EM::Twitter::Response.new('{ "status" : true }')).not_to be_empty
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
-
describe
|
108
|
-
it
|
107
|
+
describe "#reset" do
|
108
|
+
it "resets the body to an empty string" do
|
109
109
|
response = EM::Twitter::Response.new('{ "status" : true }')
|
110
|
-
response.body.length.
|
110
|
+
expect(response.body.length).to be > 0
|
111
111
|
response.reset
|
112
|
-
response.body.
|
112
|
+
expect(response.body).to eq('')
|
113
113
|
end
|
114
114
|
end
|
115
|
-
end
|
115
|
+
end
|