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