craigtmackenzie-twitter4r 0.3.1
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/CHANGES +129 -0
- data/MIT-LICENSE +20 -0
- data/README +37 -0
- data/TODO +7 -0
- data/bin/t4rsh +80 -0
- data/lib/twitter.rb +34 -0
- data/lib/twitter/client.rb +24 -0
- data/lib/twitter/client/account.rb +24 -0
- data/lib/twitter/client/auth.rb +27 -0
- data/lib/twitter/client/base.rb +93 -0
- data/lib/twitter/client/blocks.rb +35 -0
- data/lib/twitter/client/favorites.rb +53 -0
- data/lib/twitter/client/friendship.rb +35 -0
- data/lib/twitter/client/graph.rb +37 -0
- data/lib/twitter/client/messaging.rb +79 -0
- data/lib/twitter/client/profile.rb +29 -0
- data/lib/twitter/client/search.rb +27 -0
- data/lib/twitter/client/status.rb +46 -0
- data/lib/twitter/client/timeline.rb +72 -0
- data/lib/twitter/client/user.rb +65 -0
- data/lib/twitter/config.rb +77 -0
- data/lib/twitter/console.rb +31 -0
- data/lib/twitter/core.rb +137 -0
- data/lib/twitter/ext.rb +2 -0
- data/lib/twitter/ext/stdlib.rb +52 -0
- data/lib/twitter/extras.rb +39 -0
- data/lib/twitter/meta.rb +56 -0
- data/lib/twitter/model.rb +356 -0
- data/lib/twitter/version.rb +19 -0
- data/spec/twitter/client/account_spec.rb +28 -0
- data/spec/twitter/client/auth_spec.rb +34 -0
- data/spec/twitter/client/base_spec.rb +242 -0
- data/spec/twitter/client/blocks_spec.rb +76 -0
- data/spec/twitter/client/favorites_spec.rb +183 -0
- data/spec/twitter/client/friendship_spec.rb +76 -0
- data/spec/twitter/client/graph_spec.rb +67 -0
- data/spec/twitter/client/messaging_spec.rb +135 -0
- data/spec/twitter/client/profile_spec.rb +91 -0
- data/spec/twitter/client/search_spec.rb +24 -0
- data/spec/twitter/client/status_spec.rb +92 -0
- data/spec/twitter/client/timeline_spec.rb +79 -0
- data/spec/twitter/client/user_spec.rb +203 -0
- data/spec/twitter/client_spec.rb +2 -0
- data/spec/twitter/config_spec.rb +86 -0
- data/spec/twitter/console_spec.rb +15 -0
- data/spec/twitter/core_spec.rb +127 -0
- data/spec/twitter/ext/stdlib_spec.rb +59 -0
- data/spec/twitter/extras_spec.rb +46 -0
- data/spec/twitter/meta_spec.rb +90 -0
- data/spec/twitter/model_spec.rb +487 -0
- data/spec/twitter/version_spec.rb +19 -0
- metadata +114 -0
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe Hash, "#to_http_str" do
|
4
|
+
before(:each) do
|
5
|
+
@http_params = {:id => 'otherlogin', :since_id => 3953743, :full_name => 'Lucy Cross'}
|
6
|
+
@id_regexp = Regexp.new("id=#{CGI.escape(@http_params[:id].to_s)}")
|
7
|
+
@since_id_regexp = Regexp.new("since_id=#{CGI.escape(@http_params[:since_id].to_s)}")
|
8
|
+
@full_name_regexp = Regexp.new("full_name=Lucy\\+Cross")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should generate expected URL encoded string" do
|
12
|
+
http_str = @http_params.to_http_str
|
13
|
+
http_str.should match(@id_regexp)
|
14
|
+
http_str.should match(@since_id_regexp)
|
15
|
+
http_str.should match(@full_name_regexp)
|
16
|
+
end
|
17
|
+
|
18
|
+
after(:each) do
|
19
|
+
@http_params = nil
|
20
|
+
@id_kv_str, @since_id_kv_str, @full_name_kv_str = nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe Time, "#to_s" do
|
25
|
+
before(:each) do
|
26
|
+
@time = Time.now
|
27
|
+
@expected_string = @time.rfc2822
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should output RFC2822 compliant string" do
|
31
|
+
time_string = @time.to_s
|
32
|
+
time_string.should eql(@expected_string)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should respond to #old_to_s" do
|
36
|
+
@time.should respond_to(:old_to_s)
|
37
|
+
end
|
38
|
+
|
39
|
+
after(:each) do
|
40
|
+
nilize(@time, @expected_string)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# TODO: figure out how to stub the gem method to do what we want rather than this monstrousity. It is dependent on the system installation, which is always a bad thing. For now it will do so we can ship with 100% C0 coverage.
|
45
|
+
describe Kernel, "#gem_present?" do
|
46
|
+
before(:each) do
|
47
|
+
@present_gem = "rake"
|
48
|
+
@uninstalled_gem = "uninstalled-gem-crap"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should return true when a gem isn't present on system" do
|
52
|
+
gem_present?(@present_gem).should eql(true)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should return false when a gem isn't present on system" do
|
56
|
+
gem_present?(@uninstalled_gem).should eql(false)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe Twitter::Client, "#featured(:users)" do
|
4
|
+
before(:each) do
|
5
|
+
@twitter = client_context
|
6
|
+
@uris = Twitter::Client.class_eval("@@FEATURED_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
|
+
@users = [
|
12
|
+
Twitter::User.new(:screen_name => 'twitter4r'),
|
13
|
+
Twitter::User.new(:screen_name => 'dictionary'),
|
14
|
+
]
|
15
|
+
Twitter::User.stub!(:unmarshal).and_return(@users)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should create expected HTTP GET request" do
|
19
|
+
@twitter.should_receive(:create_http_get_request).with(@uris[:users]).and_return(@request)
|
20
|
+
@twitter.featured(:users)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should bless Twitter::User models returned" do
|
24
|
+
@twitter.should_receive(:bless_models).with(@users).and_return(@users)
|
25
|
+
@twitter.featured(:users)
|
26
|
+
end
|
27
|
+
|
28
|
+
after(:each) do
|
29
|
+
nilize(@twitter, @uris, @request, @response, @connection)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe Twitter::User, ".featured" do
|
34
|
+
before(:each) do
|
35
|
+
@twitter = client_context
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should delegate #featured(:users) message to given client context" do
|
39
|
+
@twitter.should_receive(:featured).with(:users).and_return([])
|
40
|
+
Twitter::User.featured(@twitter)
|
41
|
+
end
|
42
|
+
|
43
|
+
after(:each) do
|
44
|
+
nilize(@twitter)
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
def glob_files(*path_elements)
|
4
|
+
Dir.glob(File.join(*path_elements))
|
5
|
+
end
|
6
|
+
|
7
|
+
def load_erb_yaml(path, context)
|
8
|
+
ryaml = ERB.new(File.read(path), 0)
|
9
|
+
YAML.load(ryaml.result(context))
|
10
|
+
end
|
11
|
+
|
12
|
+
module ERBMetaMixin
|
13
|
+
# Needed to make the YAML load work...
|
14
|
+
def project_files
|
15
|
+
glob_files(@root_dir, 'lib', '**/*.rb')
|
16
|
+
end
|
17
|
+
|
18
|
+
# Needed to make the YAML load work...
|
19
|
+
def spec_files
|
20
|
+
glob_files(@root_dir, 'spec', '**/*_spec.rb')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "Twitter::Meta cache policy" do
|
25
|
+
include ERBMetaMixin
|
26
|
+
before(:each) do
|
27
|
+
@root_dir = project_root_dir
|
28
|
+
@meta = Twitter::Meta.new(@root_dir)
|
29
|
+
@expected_pkg_info = load_erb_yaml(File.join(@root_dir, 'pkg-info.yml'), binding)
|
30
|
+
@expected_project_files = project_files
|
31
|
+
@expected_spec_files = spec_files
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should store value returned from project_files in @project_files after first glob" do
|
35
|
+
@meta.instance_eval("@project_files").should eql(nil)
|
36
|
+
@meta.project_files
|
37
|
+
@meta.instance_eval("@project_files").should eql(@expected_project_files)
|
38
|
+
@meta.project_files
|
39
|
+
@meta.instance_eval("@project_files").should eql(@expected_project_files)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should store value returned from spec_files in @spec_files after first glob" do
|
43
|
+
@meta.instance_eval("@spec_files").should eql(nil)
|
44
|
+
@meta.spec_files
|
45
|
+
@meta.instance_eval("@spec_files").should eql(@expected_spec_files)
|
46
|
+
@meta.spec_files
|
47
|
+
@meta.instance_eval("@spec_files").should eql(@expected_spec_files)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "Twitter::Meta" do
|
52
|
+
include ERBMetaMixin
|
53
|
+
before(:each) do
|
54
|
+
@root_dir = project_root_dir
|
55
|
+
@meta = Twitter::Meta.new(@root_dir)
|
56
|
+
@expected_yaml_hash = load_erb_yaml(File.join(@root_dir, 'pkg-info.yml'), binding)
|
57
|
+
@expected_project_files = project_files
|
58
|
+
@expected_spec_files = spec_files
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should load and return YAML file into Hash object upon #pkg_info call" do
|
62
|
+
yaml_hash = @meta.pkg_info
|
63
|
+
yaml_hash.should.eql? @expected_yaml_hash
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should return the embedded hash responding to key 'spec' of #pkg_info call upon #spec_info call" do
|
67
|
+
yaml_hash = @meta.spec_info
|
68
|
+
yaml_hash.should.eql? @expected_yaml_hash['spec']
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should return list of files matching ROOT_DIR/lib/**/*.rb upon #project_files call" do
|
72
|
+
project_files = @meta.project_files
|
73
|
+
project_files.should.eql? @expected_project_files
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should return list of files matching ROOT_DIR/spec/**/*.rb upon #spec_files call" do
|
77
|
+
spec_files = @meta.spec_files
|
78
|
+
spec_files.should.eql? @expected_spec_files
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should return Gem specification based on YAML file contents and #project_files and #spec_files return values" do
|
82
|
+
spec = @meta.gem_spec
|
83
|
+
expected_spec_hash = @expected_yaml_hash['spec']
|
84
|
+
expected_spec_hash.each do |key, val|
|
85
|
+
unless val.is_a?(Hash)
|
86
|
+
spec.send(key).should.eql? expected_spec_hash[key]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,487 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
module Test
|
4
|
+
class Model
|
5
|
+
include Twitter::ModelMixin
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Twitter::Status, "unmarshaling" do
|
10
|
+
before(:each) do
|
11
|
+
@json_hash = { "text" => "Thinking Zipcar is lame...",
|
12
|
+
"id" => 46672912,
|
13
|
+
"user" => {"name" => "Angie",
|
14
|
+
"description" => "TV junkie...",
|
15
|
+
"location" => "NoVA",
|
16
|
+
"profile_image_url" => "http:\/\/assets0.twitter.com\/system\/user\/profile_image\/5483072\/normal\/eye.jpg?1177462492",
|
17
|
+
"url" => nil,
|
18
|
+
"id" => 5483072,
|
19
|
+
"protected" => false,
|
20
|
+
"screen_name" => "ang_410"},
|
21
|
+
"created_at" => "Wed May 02 03:04:54 +0000 2007"}
|
22
|
+
@user = Twitter::User.new @json_hash["user"]
|
23
|
+
@status = Twitter::Status.new @json_hash
|
24
|
+
@status.user = @user
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should respond to unmarshal class method" do
|
28
|
+
Twitter::Status.should respond_to(:unmarshal)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return expected Twitter::Status object for singular case" do
|
32
|
+
status = Twitter::Status.unmarshal(JSON.unparse(@json_hash))
|
33
|
+
status.should_not be(nil)
|
34
|
+
status.should eql(@status)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return expected array of Twitter::Status objects for plural case" do
|
38
|
+
statuses = Twitter::Status.unmarshal(JSON.unparse([@json_hash]))
|
39
|
+
statuses.should_not be(nil)
|
40
|
+
statuses.should have(1).entries
|
41
|
+
statuses.first.should eql(@status)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe Twitter::User, "unmarshaling" do
|
46
|
+
before(:each) do
|
47
|
+
@json_hash = { "name" => "Lucy Snowe",
|
48
|
+
"description" => "School Mistress Entrepreneur",
|
49
|
+
"location" => "Villette",
|
50
|
+
"url" => "http://villetteschoolforgirls.com",
|
51
|
+
"id" => 859303,
|
52
|
+
"protected" => true,
|
53
|
+
"screen_name" => "LucyDominatrix", }
|
54
|
+
@user = Twitter::User.new @json_hash
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should respond to unmarshal class method" do
|
58
|
+
Twitter::User.should respond_to(:unmarshal)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should return expected arry of Twitter::User objects for plural case" do
|
62
|
+
users = Twitter::User.unmarshal(JSON.unparse([@json_hash]))
|
63
|
+
users.should have(1).entries
|
64
|
+
users.first.should eql(@user)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should return expected Twitter::User object for singular case" do
|
68
|
+
user = Twitter::User.unmarshal(JSON.unparse(@json_hash))
|
69
|
+
user.should_not be(nil)
|
70
|
+
user.should eql(@user)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "Twitter::ModelMixin#to_hash" do
|
75
|
+
before(:all) do
|
76
|
+
class Model
|
77
|
+
include Twitter::ModelMixin
|
78
|
+
@@ATTRIBUTES = [:id, :name, :value, :unused_attr]
|
79
|
+
attr_accessor *@@ATTRIBUTES
|
80
|
+
def self.attributes; @@ATTRIBUTES; end
|
81
|
+
end
|
82
|
+
|
83
|
+
class Hash
|
84
|
+
def eql?(other)
|
85
|
+
return false unless other # trivial nil case.
|
86
|
+
return false unless self.keys.eql?(other.keys)
|
87
|
+
self.each do |key,val|
|
88
|
+
return false unless self[key].eql?(other[key])
|
89
|
+
end
|
90
|
+
true
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
before(:each) do
|
96
|
+
@attributes = {:id => 14, :name => 'State', :value => 'Illinois'}
|
97
|
+
@model = Model.new(@attributes)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should return expected hash representation of given model object" do
|
101
|
+
@model.to_hash.should eql(@attributes)
|
102
|
+
end
|
103
|
+
|
104
|
+
after(:each) do
|
105
|
+
nilize(@attributes, @model)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe Twitter::User, ".find" do
|
110
|
+
before(:each) do
|
111
|
+
@twitter = Twitter::Client.from_config 'config/twitter.yml'
|
112
|
+
@id = 2423423
|
113
|
+
@screen_name = 'ascreenname'
|
114
|
+
@expected_user = Twitter::User.new(:id => @id, :screen_name => @screen_name)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should invoke given Twitter::Client's #user method with expected arguments" do
|
118
|
+
# case where id => @id
|
119
|
+
@twitter.should_receive(:user).with(@id).and_return(@expected_user)
|
120
|
+
user = Twitter::User.find(@id, @twitter)
|
121
|
+
user.should eql(@expected_user)
|
122
|
+
|
123
|
+
# case where id => @screen_name, which is also valid
|
124
|
+
@twitter.should_receive(:user).with(@screen_name).and_return(@expected_user)
|
125
|
+
user = Twitter::User.find(@screen_name, @twitter)
|
126
|
+
user.should eql(@expected_user)
|
127
|
+
end
|
128
|
+
|
129
|
+
after(:each) do
|
130
|
+
nilize(@twitter, @id, @screen_name, @expected_user)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe Twitter::Status, ".find" do
|
135
|
+
before(:each) do
|
136
|
+
@twitter = Twitter::Client.from_config 'config/twitter.yml'
|
137
|
+
@id = 9439843
|
138
|
+
@text = 'My crummy status message'
|
139
|
+
@user = Twitter::User.new(:id => @id, :screen_name => @screen_name)
|
140
|
+
@expected_status = Twitter::Status.new(:id => @id, :text => @text, :user => @user)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should invoke given Twitter::Client's #status method with expected arguments" do
|
144
|
+
@twitter.should_receive(:status).with(:get, @id).and_return(@expected_status)
|
145
|
+
status = Twitter::Status.find(@id, @twitter)
|
146
|
+
status.should eql(@expected_status)
|
147
|
+
end
|
148
|
+
|
149
|
+
after(:each) do
|
150
|
+
nilize(@twitter, @id, @text, @user, @expected_status)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe Test::Model, "#bless" do
|
155
|
+
before(:each) do
|
156
|
+
@twitter = Twitter::Client.from_config('config/twitter.yml')
|
157
|
+
@model = Test::Model.new
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should delegate to #basic_bless" do
|
161
|
+
@model.should_receive(:basic_bless).and_return(@twitter)
|
162
|
+
@model.bless(@twitter)
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should set client attribute of self" do
|
166
|
+
@model.should_receive(:client=).once
|
167
|
+
@model.bless(@twitter)
|
168
|
+
end
|
169
|
+
|
170
|
+
after(:each) do
|
171
|
+
nilize(@model, @twitter)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe Twitter::User, "#is_me?" do
|
176
|
+
before(:each) do
|
177
|
+
@twitter = Twitter::Client.from_config('config/twitter.yml')
|
178
|
+
@user_not_me = Twitter::User.new(:screen_name => 'notmylogin')
|
179
|
+
@user_me = Twitter::User.new(:screen_name => @twitter.instance_eval("@login"))
|
180
|
+
@user_not_me.bless(@twitter)
|
181
|
+
@user_me.bless(@twitter)
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should return true when Twitter::User object represents authenticated user of client context" do
|
185
|
+
@user_me.is_me?.should be_true
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should return false when Twitter::User object does not represent authenticated user of client context" do
|
189
|
+
@user_not_me.is_me?.should be_false
|
190
|
+
end
|
191
|
+
|
192
|
+
after(:each) do
|
193
|
+
nilize(@twitter, @user_not_me, @user_me)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
describe Twitter::User, "#friends" do
|
198
|
+
before(:each) do
|
199
|
+
@twitter = Twitter::Client.from_config('config/twitter.yml')
|
200
|
+
@id = 5701682
|
201
|
+
@user = Twitter::User.new(:id => @id, :screen_name => 'twitter4r')
|
202
|
+
@user.bless(@twitter)
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should delegate to @client.user(@id, :friends)" do
|
206
|
+
@twitter.should_receive(:user).with(@id, :friends)
|
207
|
+
@user.friends
|
208
|
+
end
|
209
|
+
|
210
|
+
after(:each) do
|
211
|
+
nilize(@twitter, @id, @user)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
describe Twitter::User, "#followers" do
|
216
|
+
before(:each) do
|
217
|
+
@twitter = Twitter::Client.from_config('config/twitter.yml')
|
218
|
+
@id = 5701682
|
219
|
+
@user = Twitter::User.new(:id => @id, :screen_name => 'twitter4r')
|
220
|
+
@user.bless(@twitter)
|
221
|
+
end
|
222
|
+
|
223
|
+
it "should delegate to @client.my(:followers)" do
|
224
|
+
@twitter.should_receive(:my).with(:followers, {})
|
225
|
+
@user.followers
|
226
|
+
end
|
227
|
+
|
228
|
+
after(:each) do
|
229
|
+
nilize(@twitter, @id, @user)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
describe Test::Model, "#to_i" do
|
234
|
+
before(:each) do
|
235
|
+
@id = 234324285
|
236
|
+
class Test::Model
|
237
|
+
attr_accessor :id
|
238
|
+
end
|
239
|
+
@model = Test::Model.new(:id => @id)
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should return @id attribute" do
|
243
|
+
@model.to_i.should eql(@id)
|
244
|
+
end
|
245
|
+
|
246
|
+
after(:each) do
|
247
|
+
nilize(@model, @id)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
describe Test::Model, "#to_s" do
|
252
|
+
before(:each) do
|
253
|
+
class Test::Model
|
254
|
+
attr_accessor :text
|
255
|
+
end
|
256
|
+
@text = 'Some text for the message body here'
|
257
|
+
@model = Test::Model.new(:text => @text)
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should return expected text when a @text attribute exists for the model" do
|
261
|
+
@model.to_s.should eql(@text)
|
262
|
+
end
|
263
|
+
|
264
|
+
after(:each) do
|
265
|
+
nilize(@model)
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
describe Twitter::Message, ".find" do
|
270
|
+
it "should raise NotImplementedError due to Twitter (as opposed to Twitter4R) API limitation" do
|
271
|
+
lambda {
|
272
|
+
Twitter::Message.find(123, nil)
|
273
|
+
}.should raise_error(NotImplementedError)
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
describe Twitter::Status, ".create" do
|
278
|
+
before(:each) do
|
279
|
+
@twitter = client_context
|
280
|
+
@text = 'My status update'
|
281
|
+
@status = Twitter::Status.new(:text => @text, :client => @twitter)
|
282
|
+
end
|
283
|
+
|
284
|
+
it "should invoke #status(:post, text) on client context given" do
|
285
|
+
@twitter.should_receive(:status).with(:post, @text).and_return(@status)
|
286
|
+
Twitter::Status.create(:text => @text, :client => @twitter)
|
287
|
+
end
|
288
|
+
|
289
|
+
it "should raise an ArgumentError when no client is given in params" do
|
290
|
+
lambda {
|
291
|
+
Twitter::Status.create(:text => @text)
|
292
|
+
}.should raise_error(ArgumentError)
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should raise an ArgumentError when no text is given in params" do
|
296
|
+
@twitter.should_receive(:is_a?).with(Twitter::Client)
|
297
|
+
lambda {
|
298
|
+
Twitter::Status.create(:client => @twitter)
|
299
|
+
}.should raise_error(ArgumentError)
|
300
|
+
end
|
301
|
+
|
302
|
+
it "should raise an ArgumentError when text given in params is not a String" do
|
303
|
+
lambda {
|
304
|
+
Twitter::Status.create(:client => @twitter, :text => 234493)
|
305
|
+
}.should raise_error(ArgumentError)
|
306
|
+
end
|
307
|
+
|
308
|
+
it "should raise an ArgumentError when client context given in params is not a Twitter::Client object" do
|
309
|
+
lambda {
|
310
|
+
Twitter::Status.create(:client => 'a string instead of a Twitter::Client', :text => @text)
|
311
|
+
}.should raise_error(ArgumentError)
|
312
|
+
end
|
313
|
+
|
314
|
+
after(:each) do
|
315
|
+
nilize(@twitter, @text, @status)
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
describe Twitter::Message, ".create" do
|
320
|
+
before(:each) do
|
321
|
+
@twitter = client_context
|
322
|
+
@text = 'Just between you and I, Lantana and Gosford Park are two of my favorite movies'
|
323
|
+
@recipient = Twitter::User.new(:id => 234958)
|
324
|
+
@message = Twitter::Message.new(:text => @text, :recipient => @recipient)
|
325
|
+
end
|
326
|
+
|
327
|
+
it "should invoke #message(:post, text, recipient) on client context given" do
|
328
|
+
@twitter.should_receive(:message).with(:post, @text, @recipient).and_return(@message)
|
329
|
+
Twitter::Message.create(:client => @twitter, :text => @text, :recipient => @recipient)
|
330
|
+
end
|
331
|
+
|
332
|
+
it "should raise an ArgumentError if no client context is given in params" do
|
333
|
+
lambda {
|
334
|
+
Twitter::Message.create(:text => @text, :recipient => @recipient)
|
335
|
+
}.should raise_error(ArgumentError)
|
336
|
+
end
|
337
|
+
|
338
|
+
it "should raise an ArgumentError if client conext given in params is not a Twitter::Client object" do
|
339
|
+
lambda {
|
340
|
+
Twitter::Message.create(
|
341
|
+
:client => 3.14159,
|
342
|
+
:text => @text,
|
343
|
+
:recipient => @recipient)
|
344
|
+
}.should raise_error(ArgumentError)
|
345
|
+
end
|
346
|
+
|
347
|
+
it "should raise an ArgumentError if no text is given in params" do
|
348
|
+
@twitter.should_receive(:is_a?).with(Twitter::Client)
|
349
|
+
lambda {
|
350
|
+
Twitter::Message.create(
|
351
|
+
:client => @twitter,
|
352
|
+
:recipient => @recipient)
|
353
|
+
}.should raise_error(ArgumentError)
|
354
|
+
end
|
355
|
+
|
356
|
+
it "should raise an ArgumentError if text given in params is not a String" do
|
357
|
+
@twitter.should_receive(:is_a?).with(Twitter::Client)
|
358
|
+
lambda {
|
359
|
+
Twitter::Message.create(
|
360
|
+
:client => @twitter,
|
361
|
+
:text => Object.new,
|
362
|
+
:recipient => @recipient)
|
363
|
+
}.should raise_error(ArgumentError)
|
364
|
+
end
|
365
|
+
|
366
|
+
it "should raise an ArgumentError if no recipient is given in params" do
|
367
|
+
@text.should_receive(:is_a?).with(String)
|
368
|
+
lambda {
|
369
|
+
Twitter::Message.create(
|
370
|
+
:client => @twitter,
|
371
|
+
:text => @text)
|
372
|
+
}.should raise_error(ArgumentError)
|
373
|
+
end
|
374
|
+
|
375
|
+
it "should raise an ArgumentError if recipient given in params is not a Twitter::User, Integer or String object" do
|
376
|
+
@text.should_receive(:is_a?).with(String)
|
377
|
+
lambda {
|
378
|
+
Twitter::Message.create(
|
379
|
+
:client => @twitter,
|
380
|
+
:text => @text,
|
381
|
+
:recipient => 3.14159)
|
382
|
+
}.should raise_error(ArgumentError)
|
383
|
+
end
|
384
|
+
|
385
|
+
after(:each) do
|
386
|
+
nilize(@twitter, @text, @recipient, @message)
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
describe Twitter::User, "#befriend" do
|
391
|
+
before(:each) do
|
392
|
+
@twitter = client_context
|
393
|
+
@user = Twitter::User.new(
|
394
|
+
:id => 1234,
|
395
|
+
:screen_name => 'mylogin',
|
396
|
+
:client => @twitter)
|
397
|
+
@friend = Twitter::User.new(
|
398
|
+
:id => 5678,
|
399
|
+
:screen_name => 'friend',
|
400
|
+
:client => @twitter)
|
401
|
+
end
|
402
|
+
|
403
|
+
it "should invoke #friend(:add, user) on client context" do
|
404
|
+
@twitter.should_receive(:friend).with(:add, @friend).and_return(@friend)
|
405
|
+
@user.befriend(@friend)
|
406
|
+
end
|
407
|
+
|
408
|
+
after(:each) do
|
409
|
+
nilize(@twitter, @user, @friend)
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
describe Twitter::User, "#defriend" do
|
414
|
+
before(:each) do
|
415
|
+
@twitter = client_context
|
416
|
+
@user = Twitter::User.new(
|
417
|
+
:id => 1234,
|
418
|
+
:screen_name => 'mylogin',
|
419
|
+
:client => @twitter)
|
420
|
+
@friend = Twitter::User.new(
|
421
|
+
:id => 5678,
|
422
|
+
:screen_name => 'friend',
|
423
|
+
:client => @twitter)
|
424
|
+
end
|
425
|
+
|
426
|
+
it "should invoke #friend(:remove, user) on client context" do
|
427
|
+
@twitter.should_receive(:friend).with(:remove, @friend).and_return(@friend)
|
428
|
+
@user.defriend(@friend)
|
429
|
+
end
|
430
|
+
|
431
|
+
after(:each) do
|
432
|
+
nilize(@twitter, @user, @friend)
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
describe Twitter::Status, "#reply?" do
|
437
|
+
before(:each) do
|
438
|
+
@status = Twitter::Status.new(
|
439
|
+
:id => 123456789,
|
440
|
+
:text => "Wazzup?",
|
441
|
+
:user => mock(Twitter::User)
|
442
|
+
)
|
443
|
+
@reply = Twitter::Status.new(
|
444
|
+
:text => "No much bro. You?",
|
445
|
+
:user => mock(Twitter::User),
|
446
|
+
:in_reply_to_status_id => @status.id
|
447
|
+
)
|
448
|
+
end
|
449
|
+
|
450
|
+
it "should return false for the original status" do
|
451
|
+
@status.reply?.should be(false)
|
452
|
+
end
|
453
|
+
|
454
|
+
it "should return true for the reply to the original status" do
|
455
|
+
@reply.reply?.should be(true)
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
459
|
+
describe Twitter::Status, "#to_s" do
|
460
|
+
before(:each) do
|
461
|
+
@text = 'Aloha'
|
462
|
+
@status = Twitter::Status.new(:text => @text)
|
463
|
+
end
|
464
|
+
|
465
|
+
it "should render text attribute" do
|
466
|
+
@status.to_s.should be(@text)
|
467
|
+
end
|
468
|
+
|
469
|
+
after(:each) do
|
470
|
+
nilize(@text, @status)
|
471
|
+
end
|
472
|
+
end
|
473
|
+
|
474
|
+
describe Twitter::Message, "#to_s" do
|
475
|
+
before(:each) do
|
476
|
+
@text = 'Aloha'
|
477
|
+
@message = Twitter::Message.new(:text => @text)
|
478
|
+
end
|
479
|
+
|
480
|
+
it "should render text attribute" do
|
481
|
+
@message.to_s.should be(@text)
|
482
|
+
end
|
483
|
+
|
484
|
+
after(:each) do
|
485
|
+
nilize(@text, @message)
|
486
|
+
end
|
487
|
+
end
|