mbbx6spp-twitter4r 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/CHANGES +124 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README +32 -0
  4. data/TODO +9 -0
  5. data/lib/twitter/client/account.rb +24 -0
  6. data/lib/twitter/client/auth.rb +27 -0
  7. data/lib/twitter/client/base.rb +87 -0
  8. data/lib/twitter/client/blocks.rb +35 -0
  9. data/lib/twitter/client/favorites.rb +53 -0
  10. data/lib/twitter/client/friendship.rb +35 -0
  11. data/lib/twitter/client/messaging.rb +79 -0
  12. data/lib/twitter/client/status.rb +46 -0
  13. data/lib/twitter/client/timeline.rb +72 -0
  14. data/lib/twitter/client/user.rb +65 -0
  15. data/lib/twitter/client.rb +21 -0
  16. data/lib/twitter/config.rb +71 -0
  17. data/lib/twitter/console.rb +28 -0
  18. data/lib/twitter/core.rb +137 -0
  19. data/lib/twitter/ext/stdlib.rb +51 -0
  20. data/lib/twitter/ext.rb +2 -0
  21. data/lib/twitter/extras.rb +39 -0
  22. data/lib/twitter/meta.rb +56 -0
  23. data/lib/twitter/model.rb +348 -0
  24. data/lib/twitter/rails.rb +92 -0
  25. data/lib/twitter/version.rb +19 -0
  26. data/lib/twitter.rb +31 -0
  27. data/spec/twitter/client/auth_spec.rb +34 -0
  28. data/spec/twitter/client/base_spec.rb +242 -0
  29. data/spec/twitter/client/blocks_spec.rb +76 -0
  30. data/spec/twitter/client/favorites_spec.rb +183 -0
  31. data/spec/twitter/client/friendship_spec.rb +76 -0
  32. data/spec/twitter/client/messaging_spec.rb +135 -0
  33. data/spec/twitter/client/status_spec.rb +92 -0
  34. data/spec/twitter/client/timeline_spec.rb +79 -0
  35. data/spec/twitter/client/user_spec.rb +203 -0
  36. data/spec/twitter/client_spec.rb +2 -0
  37. data/spec/twitter/config_spec.rb +86 -0
  38. data/spec/twitter/console_spec.rb +15 -0
  39. data/spec/twitter/core_spec.rb +127 -0
  40. data/spec/twitter/ext/stdlib_spec.rb +42 -0
  41. data/spec/twitter/extras_spec.rb +46 -0
  42. data/spec/twitter/meta_spec.rb +90 -0
  43. data/spec/twitter/model_spec.rb +464 -0
  44. data/spec/twitter/rails_spec.rb +110 -0
  45. data/spec/twitter/version_spec.rb +19 -0
  46. metadata +108 -0
@@ -0,0 +1,135 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ describe Twitter::Client, "#messages" do
4
+ before(:each) do
5
+ @twitter = client_context
6
+ @uris = Twitter::Client.class_eval("@@MESSAGING_URIS")
7
+ @request = mas_net_http_get(:basic_auth => nil)
8
+ @response = mas_net_http_response(:success, "[]")
9
+ @connection = mas_net_http(@response)
10
+ Net::HTTP.stub!(:new).and_return(@connection)
11
+ @messages = []
12
+ Twitter::Message.stub!(:unmarshal).and_return(@messages)
13
+ @page = 2
14
+ end
15
+
16
+ it "should create expected HTTP GET request for :received case" do
17
+ @twitter.should_receive(:create_http_get_request).with(@uris[:received], {}).and_return(@request)
18
+ @twitter.messages(:received)
19
+ end
20
+
21
+ it "should bless the Array returned from Twitter for :received case" do
22
+ @twitter.should_receive(:bless_models).with(@messages).and_return(@messages)
23
+ @twitter.messages(:received)
24
+ end
25
+
26
+ it "should create expected HTTP GET request for :sent case" do
27
+ @twitter.should_receive(:create_http_get_request).with(@uris[:sent], {}).and_return(@request)
28
+ @twitter.messages(:sent)
29
+ end
30
+
31
+ it "should bless the Array returned from Twitter for :sent case" do
32
+ @twitter.should_receive(:bless_models).with(@messages).and_return(@messages)
33
+ @twitter.messages(:sent)
34
+ end
35
+
36
+ it "should raise an ArgumentError when giving an invalid messaging action" do
37
+ lambda {
38
+ @twitter.messages(:crap)
39
+ }.should raise_error(ArgumentError)
40
+ end
41
+
42
+ it "should accept an options Hash for paging" do
43
+ lambda {
44
+ @twitter.messages(:sent, :page => @page)
45
+ }.should_not raise_error(Exception)
46
+ end
47
+
48
+ it "should generate expected GET HTTP request for paging case" do
49
+ @twitter.should_receive(:create_http_get_request).with(@uris[:received], {:page => @page}).and_return(@request)
50
+ @twitter.messages(:received, :page => @page)
51
+ end
52
+
53
+ it "should bless models for paging case" do
54
+ @twitter.should_receive(:bless_models).with(@messages).and_return(@messages)
55
+ @twitter.messages(:sent, :page => @page)
56
+ end
57
+
58
+ after(:each) do
59
+ nilize(@twitter, @uris, @request, @response, @connection, @messages)
60
+ end
61
+ end
62
+
63
+ describe Twitter::Client, "#message" do
64
+ before(:each) do
65
+ @twitter = client_context
66
+ @attributes = {
67
+ :id => 34324,
68
+ :text => 'Randy, are you coming over later?',
69
+ :sender => {:id => 123, :screen_name => 'mylogin'},
70
+ :recipient => {:id => 1234, :screen_name => 'randy'},
71
+ }
72
+ @message = Twitter::Message.new(@attributes)
73
+ @uris = Twitter::Client.class_eval("@@MESSAGING_URIS")
74
+ @request = mas_net_http_get(:basic_auth => nil)
75
+ @json = JSON.unparse(@attributes)
76
+ @response = mas_net_http_response(:success, @json)
77
+ @connection = mas_net_http(@response)
78
+ @source = Twitter::Client.class_eval("@@defaults[:source]")
79
+
80
+ Net::HTTP.stub!(:new).and_return(@connection)
81
+ Twitter::Message.stub!(:unmarshal).and_return(@message)
82
+ end
83
+
84
+ it "should invoke #http_connect with expected arguments for :post case" do
85
+ @twitter.should_receive(:http_connect).with({:text => @message.text, :user => @message.recipient.to_i, :source => @source}.to_http_str).and_return(@response)
86
+ @twitter.message(:post, @message.text, @message.recipient)
87
+ end
88
+
89
+ it "should create expected HTTP POST request for :post case" do
90
+ @twitter.should_receive(:create_http_post_request).with(@uris[:post]).and_return(@request)
91
+ @twitter.message(:post, @message.text, @message.recipient)
92
+ end
93
+
94
+ it "should bless returned Twitter::Message object for :post case" do
95
+ @twitter.should_receive(:bless_model).with(@message)
96
+ @twitter.message(:post, @message.text, @message.recipient)
97
+ end
98
+
99
+ it "should create expected HTTP DELETE request for :delete case" do
100
+ @twitter.should_receive(:create_http_delete_request).with(@uris[:delete], {:id => @message.to_i}).and_return(@request)
101
+ @twitter.message(:delete, @message)
102
+ end
103
+
104
+ it "should bless returned Twitter::Message object for :delete case" do
105
+ @twitter.should_receive(:bless_model).with(@message)
106
+ @twitter.message(:delete, @message)
107
+ end
108
+
109
+ it "should invoke #to_i on message object passed in for :delete case" do
110
+ @message.should_receive(:to_i).and_return(@message.id)
111
+ @twitter.message(:delete, @message)
112
+ end
113
+
114
+ it "should raise an ArgumentError when giving an invalid messaging action" do
115
+ lambda {
116
+ @twitter.message(:crap, @message)
117
+ }.should raise_error(ArgumentError)
118
+ end
119
+
120
+ it "should raise an ArgumentError for :post case if user argument is not supplied" do
121
+ lambda {
122
+ @twitter.message(:post, @message)
123
+ }.should raise_error(ArgumentError)
124
+ end
125
+
126
+ it "should raise an ArgumentError for :post case if user argument is nil" do
127
+ lambda {
128
+ @twitter.message(:post, @message, nil)
129
+ }.should raise_error(ArgumentError)
130
+ end
131
+
132
+ after(:each) do
133
+ nilize(@twitter, @uris, @request, @response, @connection, @sender, @recipient, @message, @attributes)
134
+ end
135
+ end
@@ -0,0 +1,92 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ describe Twitter::Client, "#status" do
4
+ before(:each) do
5
+ @twitter = client_context
6
+ @message = 'This is my unique message'
7
+ @uris = Twitter::Client.class_eval("@@STATUS_URIS")
8
+ @options = {:id => 666666}
9
+ @request = mas_net_http_get(:basic_auth => nil)
10
+ @response = mas_net_http_response(:success, '{}')
11
+ @connection = mas_net_http(@response)
12
+ @float = 43.3434
13
+ @status = Twitter::Status.new(:id => 2349343)
14
+ @source = Twitter::Client.class_eval("@@defaults[:source]")
15
+ end
16
+
17
+ it "should return nil if nil is passed as value argument for :get case" do
18
+ status = @twitter.status(:get, nil)
19
+ status.should be_nil
20
+ end
21
+
22
+ it "should not call @twitter#http_connect when passing nil for value argument in :get case" do
23
+ @twitter.should_not_receive(:http_connect)
24
+ @twitter.status(:get, nil)
25
+ end
26
+
27
+ it "should create expected HTTP GET request for :get case" do
28
+ @twitter.should_receive(:create_http_get_request).with(@uris[:get], @options).and_return(@request)
29
+ @twitter.status(:get, @options[:id])
30
+ end
31
+
32
+ it "should invoke @twitter#create_http_get_request with given parameters equivalent to {:id => value.to_i} for :get case" do
33
+ # Float case
34
+ @twitter.should_receive(:create_http_get_request).with(@uris[:get], {:id => @float.to_i}).and_return(@request)
35
+ @twitter.status(:get, @float)
36
+
37
+ # Twitter::Status object case
38
+ @twitter.should_receive(:create_http_get_request).with(@uris[:get], {:id => @status.to_i}).and_return(@request)
39
+ @twitter.status(:get, @status)
40
+ end
41
+
42
+ it "should return nil if nil is passed as value argument for :post case" do
43
+ status = @twitter.status(:post, nil)
44
+ status.should be_nil
45
+ end
46
+
47
+ it "should not call @twitter#http_connect when passing nil for value argument in :post case" do
48
+ @twitter.should_not_receive(:http_connect)
49
+ @twitter.status(:post, nil)
50
+ end
51
+
52
+ it "should create expected HTTP POST request for :post case" do
53
+ @twitter.should_receive(:create_http_post_request).with(@uris[:post]).and_return(@request)
54
+ @connection.should_receive(:request).with(@request, {:status => @message, :source => @source}.to_http_str).and_return(@response)
55
+ @twitter.status(:post, @message)
56
+ end
57
+
58
+ it "should return nil if nil is passed as value argument for :delete case" do
59
+ status = @twitter.status(:delete, nil)
60
+ status.should be_nil
61
+ end
62
+
63
+ it "should not call @twitter#http_connect when passing nil for value argument in :delete case" do
64
+ @twitter.should_not_receive(:http_connect)
65
+ @twitter.status(:delete, nil)
66
+ end
67
+
68
+ it "should create expected HTTP DELETE request for :delete case" do
69
+ @twitter.should_receive(:create_http_delete_request).with(@uris[:delete], @options).and_return(@request)
70
+ @twitter.status(:delete, @options[:id])
71
+ end
72
+
73
+ it "should invoke @twitter#create_http_get_request with given parameters equivalent to {:id => value.to_i} for :delete case" do
74
+ # Float case
75
+ @twitter.should_receive(:create_http_delete_request).with(@uris[:delete], {:id => @float.to_i}).and_return(@request)
76
+ @twitter.status(:delete, @float)
77
+
78
+ # Twitter::Status object case
79
+ @twitter.should_receive(:create_http_delete_request).with(@uris[:delete], {:id => @status.to_i}).and_return(@request)
80
+ @twitter.status(:delete, @status)
81
+ end
82
+
83
+ it "should raise an ArgumentError when given an invalid status action" do
84
+ lambda {
85
+ @twitter.status(:crap, nil)
86
+ }.should raise_error(ArgumentError)
87
+ end
88
+
89
+ after(:each) do
90
+ nilize(@twitter)
91
+ end
92
+ end
@@ -0,0 +1,79 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ describe Twitter::Client, "Timeline API" do
4
+ before(:each) do
5
+ @client = client_context
6
+ @uris = Twitter::Client.class_eval("@@TIMELINE_URIS")
7
+ @user = Twitter::User.new(:screen_name => 'mylogin')
8
+ @status = Twitter::Status.new(:id => 23343443, :text => 'I love Lucy!', :user => @user)
9
+ @timeline = [@status]
10
+ @json = JSON.unparse([@status.to_hash])
11
+ @request = mas_net_http_get(:basic_auth => nil)
12
+ @response = mas_net_http_response(:success, @json)
13
+ @connection = mas_net_http(@response)
14
+ @params = {
15
+ :public => {:since_id => 3249328},
16
+ :friends => {:id => 'myfriend'},
17
+ :user => {:id => 'auser'},
18
+ :me => {},
19
+ }
20
+ end
21
+
22
+ it "should respond to instance method #timeline_for" do
23
+ @client.should respond_to(:timeline_for)
24
+ end
25
+
26
+ it "should call #http_get with expected parameters for :public case" do
27
+ @client.should_receive(:http_connect).and_return(mas_net_http_response(:success, @json))
28
+ @client.timeline_for(:public)
29
+ end
30
+
31
+ it "should yield to block for each status in timeline" do
32
+ @client.should_receive(:http_connect).and_return(mas_net_http_response(:success, @json))
33
+ Twitter::Status.should_receive(:unmarshal).and_return(@timeline)
34
+ count = 0
35
+ @client.timeline_for(:public) do |status|
36
+ status.should eql(@status)
37
+ count += 1
38
+ end
39
+ count.should eql(@timeline.size)
40
+ end
41
+
42
+ it "should generate expected HTTP GET request for generic :public case" do
43
+ @client.should_receive(:create_http_get_request).with(@uris[:public], {}).and_return(@request)
44
+ timeline = @client.timeline_for(:public)
45
+ timeline.should eql(@timeline)
46
+ end
47
+
48
+ it "should generate expected HTTP GET request for :public case with expected parameters" do
49
+ @client.should_receive(:create_http_get_request).with(@uris[:public], @params[:public]).and_return(@request)
50
+ timeline = @client.timeline_for(:public, @params[:public])
51
+ timeline.should eql(@timeline)
52
+ end
53
+
54
+ it "should generate expected HTTP GET request for generic :friends case" do
55
+ @client.should_receive(:create_http_get_request).with(@uris[:friends], {}).and_return(@request)
56
+ timeline = @client.timeline_for(:friends)
57
+ timeline.should eql(@timeline)
58
+ end
59
+
60
+ it "should generate expected HTTP GET request for :friends case with expected parameters" do
61
+ @client.should_receive(:create_http_get_request).with(@uris[:friends], @params[:friends]).and_return(@request)
62
+ timeline = @client.timeline_for(:friends, @params[:friends])
63
+ timeline.should eql(@timeline)
64
+ end
65
+
66
+ it "should raise an ArgumentError if type given is not valid" do
67
+ lambda {
68
+ @client.timeline_for(:crap)
69
+ }.should raise_error(ArgumentError)
70
+
71
+ lambda {
72
+ @client.timeline_for(:crap, @params[:friends])
73
+ }.should raise_error(ArgumentError)
74
+ end
75
+
76
+ after(:each) do
77
+ nilize(@client)
78
+ end
79
+ end
@@ -0,0 +1,203 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ describe Twitter::Client, "#user(id, :info)" do
4
+ before(:each) do
5
+ @twitter = client_context
6
+ @id = 395783
7
+ @screen_name = 'boris_johnson_is_funny_as_hell'
8
+ @user = Twitter::User.new(
9
+ :id => @id,
10
+ :screen_name => @screen_name,
11
+ :location => 'London'
12
+ )
13
+ @json = JSON.unparse(@user.to_hash)
14
+ @request = mas_net_http_get(:basic_auth => nil)
15
+ @response = mas_net_http_response(:success, @json)
16
+ @connection = mas_net_http(@response)
17
+ @uris = Twitter::Client.class_eval("@@USER_URIS")
18
+ @twitter.stub!(:create_http_get_request).and_return(@request)
19
+ Twitter::User.stub!(:unmarshal).and_return(@user)
20
+ Net::HTTP.stub!(:new).and_return(@connection)
21
+ end
22
+
23
+ it "should create expected HTTP GET request when giving numeric user id" do
24
+ @twitter.should_receive(:create_http_get_request).with(@uris[:info], {:id => @id}).and_return(@request)
25
+ @twitter.user(@id)
26
+ end
27
+
28
+ it "should create expected HTTP GET request when giving screen name" do
29
+ @twitter.should_receive(:create_http_get_request).with(@uris[:info], {:id => @screen_name}).and_return(@request)
30
+ @twitter.user(@screen_name)
31
+ end
32
+
33
+ it "should bless model returned when giving numeric user id" do
34
+ @twitter.should_receive(:bless_model).with(@user).and_return(@user)
35
+ @twitter.user(@id)
36
+ end
37
+
38
+ it "should bless model returned when giving screen name" do
39
+ @twitter.should_receive(:bless_model).with(@user).and_return(@user)
40
+ @twitter.user(@screen_name)
41
+ end
42
+
43
+ after(:each) do
44
+ nilize(@request, @response, @connection, @twitter, @id, @screen_name, @user)
45
+ end
46
+ end
47
+
48
+ # TODO: Add specs for new Twitter::Client#user(id, :friends) and
49
+ # Twitter::Client#user(id, :followers) use cases.
50
+ describe Twitter::Client, "#user(id, :friends)" do
51
+ before(:each) do
52
+ @twitter = client_context
53
+ @id = 395784
54
+ @screen_name = 'cafe_paradiso'
55
+ @user = Twitter::User.new(
56
+ :id => @id,
57
+ :screen_name => @screen_name,
58
+ :location => 'Urbana, IL'
59
+ )
60
+ @json = JSON.unparse(@user.to_hash)
61
+ @request = mas_net_http_get(:basic_auth => nil)
62
+ @response = mas_net_http_response(:success, @json)
63
+ @connection = mas_net_http(@response)
64
+ @uris = Twitter::Client.class_eval("@@USER_URIS")
65
+ @twitter.stub!(:create_http_get_request).and_return(@request)
66
+ Twitter::User.stub!(:unmarshal).and_return(@user)
67
+ Net::HTTP.stub!(:new).and_return(@connection)
68
+ end
69
+
70
+ it "should create expected HTTP GET request when giving numeric user id" do
71
+ @twitter.should_receive(:create_http_get_request).with(@uris[:friends], {:id => @id}).and_return(@request)
72
+ @twitter.user(@id, :friends)
73
+ end
74
+
75
+ it "should invoke #to_i on Twitter::User objecct given" do
76
+ @user.should_receive(:to_i).and_return(@id)
77
+ @twitter.user(@user, :friends)
78
+ end
79
+
80
+ it "should create expected HTTP GET request when giving Twitter::User object" do
81
+ @twitter.should_receive(:create_http_get_request).with(@uris[:friends], {:id => @user.to_i}).and_return(@request)
82
+ @twitter.user(@user, :friends)
83
+ end
84
+
85
+ it "should create expected HTTP GET request when giving screen name" do
86
+ @twitter.should_receive(:create_http_get_request).with(@uris[:friends], {:id => @screen_name}).and_return(@request)
87
+ @twitter.user(@screen_name, :friends)
88
+ end
89
+
90
+ it "should bless model returned when giving numeric id" do
91
+ @twitter.should_receive(:bless_model).with(@user).and_return(@user)
92
+ @twitter.user(@id, :friends)
93
+ end
94
+
95
+ it "should bless model returned when giving Twitter::User object" do
96
+ @twitter.should_receive(:bless_model).with(@user).and_return(@user)
97
+ @twitter.user(@user, :friends)
98
+ end
99
+
100
+ it "should bless model returned when giving screen name" do
101
+ @twitter.should_receive(:bless_model).with(@user).and_return(@user)
102
+ @twitter.user(@screen_name, :friends)
103
+ end
104
+
105
+ after(:each) do
106
+ nilize(@request, @response, @connection, @twitter, @id, @screen_name, @user)
107
+ end
108
+ end
109
+
110
+ describe Twitter::Client, "#my(:info)" do
111
+ before(:each) do
112
+ @twitter = client_context
113
+ @screen_name = @twitter.instance_eval("@login")
114
+ @user = Twitter::User.new(
115
+ :id => 2394393,
116
+ :screen_name => @screen_name,
117
+ :location => 'Glamorous Urbana'
118
+ )
119
+ @json = JSON.unparse(@user.to_hash)
120
+ @request = mas_net_http_get(:basic_auth => nil)
121
+ @response = mas_net_http_response(:success, @json)
122
+ @connection = mas_net_http(@response)
123
+ @uris = Twitter::Client.class_eval("@@USER_URIS")
124
+ @twitter.stub!(:create_http_get_request).and_return(@request)
125
+ Net::HTTP.stub!(:new).and_return(@connection)
126
+ Twitter::User.stub!(:unmarshal).and_return(@user)
127
+ end
128
+
129
+ it "should create expected HTTP GET request" do
130
+ @twitter.should_receive(:create_http_get_request).with(@uris[:info], :id => @screen_name).and_return(@request)
131
+ @twitter.my(:info)
132
+ end
133
+
134
+ it "should bless the model object returned" do
135
+ @twitter.should_receive(:bless_models).with(@user).and_return(@user)
136
+ @twitter.my(:info)
137
+ end
138
+
139
+ it "should return expected user object" do
140
+ user = @twitter.my(:info)
141
+ user.should eql(@user)
142
+ end
143
+
144
+ after(:each) do
145
+ nilize(@request, @response, @connection, @twitter, @user, @screen_name)
146
+ end
147
+ end
148
+
149
+ describe Twitter::Client, "#my(:friends)" do
150
+ before(:each) do
151
+ @twitter = client_context
152
+ @screen_name = @twitter.instance_eval("@login")
153
+ @friends = [
154
+ Twitter::User.new(:screen_name => 'lucy_snowe'),
155
+ Twitter::User.new(:screen_name => 'jane_eyre'),
156
+ Twitter::User.new(:screen_name => 'tess_derbyfield'),
157
+ Twitter::User.new(:screen_name => 'elizabeth_jane_newson'),
158
+ ]
159
+ @json = JSON.unparse(@friends.collect {|f| f.to_hash })
160
+ @request = mas_net_http_get(:basic_auth => nil)
161
+ @response = mas_net_http_response(:success, @json)
162
+ @connection = mas_net_http(@response)
163
+ @uris = Twitter::Client.class_eval("@@USER_URIS")
164
+ @twitter.stub!(:create_http_get_request).and_return(@request)
165
+ Twitter::User.stub!(:unmarshal).and_return(@friends)
166
+ Net::HTTP.stub!(:new).and_return(@connection)
167
+ end
168
+
169
+ it "should create expected HTTP GET request" do
170
+ @twitter.should_receive(:create_http_get_request).with(@uris[:friends], :id => @screen_name).and_return(@request)
171
+ @twitter.my(:friends)
172
+ end
173
+
174
+ it "should bless models returned" do
175
+ @twitter.should_receive(:bless_models).with(@friends).and_return(@friends)
176
+ @twitter.my(:friends)
177
+ end
178
+
179
+ it "should return expected Array of friends" do
180
+ friends = @twitter.my(:friends)
181
+ friends.should eql(@friends)
182
+ end
183
+
184
+ after(:each) do
185
+ nilize(@request, @response, @connection, @twitter, @friends, @screen_name)
186
+ end
187
+ end
188
+
189
+ describe Twitter::Client, "#my(:invalid_action)" do
190
+ before(:each) do
191
+ @twitter = client_context
192
+ end
193
+
194
+ it "should raise ArgumentError for invalid user action" do
195
+ lambda {
196
+ @twitter.my(:crap)
197
+ }.should raise_error(ArgumentError)
198
+ end
199
+
200
+ after(:each) do
201
+ nilize(@twitter)
202
+ end
203
+ end
@@ -0,0 +1,2 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
@@ -0,0 +1,86 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe Twitter::Client, ".configure" do
4
+ it "should respond to :configure class method" do
5
+ Twitter::Client.respond_to?(:configure).should be(true)
6
+ end
7
+
8
+ it "should not accept calls that do not specify blocks" do
9
+ lambda {
10
+ Twitter::Client.configure()
11
+ }.should raise_error(ArgumentError)
12
+ end
13
+ end
14
+
15
+ describe Twitter::Client, ".configure with mocked @config" do
16
+ before(:each) do
17
+ @block_invoked = false
18
+ @conf_yielded = false
19
+ @conf = mock(Twitter::Config)
20
+ @block = Proc.new do |conf|
21
+ @block_invoked = true
22
+ @conf_yielded = true if conf.is_a?(Twitter::Config)
23
+ end
24
+ Twitter::Config.stub!(:new).and_return(@conf)
25
+ end
26
+
27
+ it "should not raise an error when passing block" do
28
+ lambda {
29
+ Twitter::Client.configure(&@block)
30
+ }.should_not raise_error
31
+ end
32
+
33
+ it "should yield a Twitter::Client object to block" do
34
+ Twitter::Client.configure(&@block)
35
+ @block_invoked.should be(true)
36
+ @conf_yielded.should be(true)
37
+ end
38
+
39
+ after(:each) do
40
+ nilize(@block, @block_invoked, @conf, @conf_yielded)
41
+ end
42
+ end
43
+
44
+ describe Twitter::Config, "#eql?" do
45
+ before(:each) do
46
+ @protocol = :ssl
47
+ @host = 'twitter.com'
48
+ @port = 443
49
+ @proxy_host = 'myproxy.host'
50
+ @proxy_port = 8080
51
+ attrs = {
52
+ :protocol => @protocol,
53
+ :host => @host,
54
+ :port => @port,
55
+ :proxy_host => @proxy_host,
56
+ :proxy_port => @proxy_port,
57
+ }
58
+ @obj = Twitter::Config.new(attrs)
59
+ @other = Twitter::Config.new(attrs)
60
+
61
+ @different = stubbed_twitter_config(Twitter::Config.new, attrs.merge(:proxy_host => 'different.proxy'))
62
+ @same = @obj
63
+ end
64
+
65
+ it "should return true for two logically equivalent objects" do
66
+ @obj.should be_eql(@other)
67
+ @other.should be_eql(@obj)
68
+ end
69
+
70
+ it "should return false for two logically different objects" do
71
+ @obj.should_not be_eql(@different)
72
+ @different.should_not be_eql(@obj)
73
+ @other.should_not be_eql(@different)
74
+ @different.should_not be_eql(@other)
75
+ end
76
+
77
+ it "should return true for references to the same object in memory" do
78
+ @obj.should eql(@same)
79
+ @same.should eql(@obj)
80
+ @other.should eql(@other)
81
+ end
82
+
83
+ after(:each) do
84
+ nilize(@protocol, @host, @port, @proxy_host, @proxy_port, @obj, @other, @different, @same)
85
+ end
86
+ end
@@ -0,0 +1,15 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe Twitter::Client, ".from_config" do
4
+ before(:each) do
5
+
6
+ end
7
+
8
+ it "should load YAML file for instance configuration" do
9
+
10
+ end
11
+
12
+ after(:each) do
13
+
14
+ end
15
+ end