www-delicious 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +41 -0
- data/{MIT-LICENSE → MIT-LICENSE.rdoc} +0 -0
- data/Manifest +49 -0
- data/{README → README.rdoc} +13 -14
- data/Rakefile +36 -118
- data/TODO +4 -0
- data/lib/www/delicious.rb +527 -446
- data/lib/www/delicious/bundle.rb +41 -22
- data/lib/www/delicious/element.rb +72 -0
- data/lib/www/delicious/errors.rb +2 -2
- data/lib/www/delicious/post.rb +71 -61
- data/lib/www/delicious/tag.rb +43 -62
- data/lib/www/delicious/version.rb +1 -1
- data/test/fixtures/net_response_invalid_account.yml +25 -0
- data/test/fixtures/net_response_success.yml +23 -0
- data/test/helper.rb +19 -79
- data/test/test_all.rb +17 -0
- data/test/test_offline.rb +17 -0
- data/test/test_online.rb +19 -0
- data/test/testcases/element/bundle.xml +1 -0
- data/test/testcases/element/invalid_root.xml +2 -0
- data/test/testcases/element/post.xml +2 -0
- data/test/testcases/element/post_unshared.xml +2 -0
- data/test/testcases/element/tag.xml +1 -0
- data/test/testcases/response/bundles_all.xml +5 -0
- data/test/testcases/response/bundles_all_empty.xml +2 -0
- data/test/testcases/response/bundles_delete.xml +2 -0
- data/test/testcases/response/bundles_set.xml +2 -0
- data/test/testcases/response/bundles_set_error.xml +2 -0
- data/test/testcases/response/posts_add.xml +2 -0
- data/test/testcases/response/posts_all.xml +12 -0
- data/test/testcases/response/posts_dates.xml +14 -0
- data/test/testcases/response/posts_dates_with_tag.xml +14 -0
- data/test/testcases/response/posts_delete.xml +2 -0
- data/test/testcases/response/posts_get.xml +7 -0
- data/test/testcases/response/posts_get_with_tag.xml +6 -0
- data/test/testcases/response/posts_recent.xml +19 -0
- data/test/testcases/response/posts_recent_with_tag.xml +19 -0
- data/test/testcases/response/tags_get.xml +5 -0
- data/test/testcases/response/tags_get_empty.xml +2 -0
- data/test/testcases/response/tags_rename.xml +2 -0
- data/test/testcases/response/update.delicious1.xml +2 -0
- data/test/testcases/response/update.xml +3 -0
- data/test/unit/bundle_test.rb +62 -0
- data/test/unit/delicious_test.rb +186 -238
- data/test/unit/online/online_test.rb +147 -0
- data/test/unit/post_test.rb +67 -0
- data/test/unit/tag_test.rb +68 -0
- data/www-delicious.gemspec +146 -0
- metadata +85 -31
- data/CHANGELOG +0 -5
- data/test/unit/delicious_bundle_test.rb +0 -90
- data/test/unit/delicious_online_test.rb +0 -143
- data/test/unit/delicious_post_test.rb +0 -102
- data/test/unit/delicious_tag_test.rb +0 -140
data/test/unit/delicious_test.rb
CHANGED
@@ -17,53 +17,30 @@ require File.dirname(__FILE__) + '/../helper'
|
|
17
17
|
|
18
18
|
|
19
19
|
class DeliciousTest < Test::Unit::TestCase
|
20
|
-
include WWW::Delicious::TestCase
|
21
20
|
|
21
|
+
TEST_USERNAME = 'username'
|
22
|
+
TEST_PASSWORD = 'password'
|
22
23
|
|
23
|
-
# =========================================================================
|
24
|
-
# Constructor behavior
|
25
|
-
# =========================================================================
|
26
24
|
|
27
|
-
def
|
28
|
-
|
29
|
-
assert_nothing_raised() { obj = WWW::Delicious.new(TEST_USERNAME, TEST_PASSWORD) }
|
30
|
-
assert_instance_of(WWW::Delicious, obj)
|
25
|
+
def setup
|
26
|
+
@delicious = instance
|
31
27
|
end
|
32
28
|
|
33
|
-
def test_initialize_with_block
|
34
|
-
obj = instance do |delicious|
|
35
|
-
assert_instance_of(WWW::Delicious, delicious)
|
36
|
-
end
|
37
|
-
assert_instance_of(WWW::Delicious, obj)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_initialize_with_options
|
41
|
-
obj = nil
|
42
|
-
assert_nothing_raised() { obj = WWW::Delicious.new(TEST_USERNAME, TEST_PASSWORD, {:user_agent => 'ruby/test'}) }
|
43
|
-
assert_instance_of(WWW::Delicious, obj)
|
44
|
-
end
|
45
29
|
|
46
30
|
def test_initialize_raises_without_account
|
47
31
|
assert_raise(ArgumentError) { WWW::Delicious.new() }
|
48
32
|
assert_raise(ArgumentError) { WWW::Delicious.new(TEST_USERNAME) }
|
49
33
|
end
|
50
|
-
|
51
|
-
|
52
|
-
# =========================================================================
|
53
|
-
# Constructor options
|
54
|
-
# =========================================================================
|
55
34
|
|
56
35
|
def test_initialize_account
|
57
|
-
|
58
|
-
assert_equal(
|
59
|
-
assert_equal(@default_password, obj.password)
|
36
|
+
assert_equal(TEST_USERNAME, @delicious.username)
|
37
|
+
assert_equal(TEST_PASSWORD, @delicious.password)
|
60
38
|
end
|
61
39
|
|
62
40
|
def test_initialize_option_user_agent
|
63
|
-
obj = nil
|
64
41
|
useragent = 'MyClass/1.0 (Foo/Bar +http://foo.com/)'
|
65
|
-
|
66
|
-
assert_equal(useragent,
|
42
|
+
delicious = instance(:user_agent => useragent)
|
43
|
+
assert_equal(useragent, delicious.user_agent)
|
67
44
|
end
|
68
45
|
|
69
46
|
def test_initialize_option_user_agent_default
|
@@ -71,80 +48,86 @@ class DeliciousTest < Test::Unit::TestCase
|
|
71
48
|
assert_match("Ruby/#{RUBY_VERSION}", useragent)
|
72
49
|
assert_match("#{WWW::Delicious::NAME}/#{WWW::Delicious::VERSION}", useragent)
|
73
50
|
end
|
74
|
-
|
51
|
+
|
52
|
+
def test_initialize_option_base_uri
|
53
|
+
base_uri = 'https://ma.gnolia.com/api/mirrord'
|
54
|
+
delicious = instance(:base_uri => base_uri)
|
55
|
+
assert_equal(URI.parse(base_uri), delicious.base_uri)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_initialize_option_base_uri_default
|
59
|
+
base_uri = instance.base_uri
|
60
|
+
assert_equal(URI.parse('https://api.del.icio.us'), base_uri)
|
61
|
+
end
|
62
|
+
|
75
63
|
|
76
64
|
# =========================================================================
|
77
|
-
#
|
78
|
-
# Even if #request is a protected method, it is so important that
|
79
|
-
# we must test it separately as we did for a few other similar methods.
|
65
|
+
# HTTP Request common checks
|
80
66
|
# =========================================================================
|
81
67
|
|
82
68
|
def test_request_raises_without_http_client
|
83
|
-
|
84
|
-
|
85
|
-
assert_raise(WWW::Delicious::Error) { obj.send(:request, '/foo') }
|
69
|
+
@delicious.http_client = nil
|
70
|
+
assert_raise(WWW::Delicious::Error) { @delicious.update }
|
86
71
|
end
|
87
|
-
|
88
|
-
def test_request_waits_necessary_time_between_requests
|
89
|
-
# use valid_account? as a safe request to prevent tests
|
90
|
-
# run with invalid credential to fail
|
91
|
-
r = File.read(TESTCASE_PATH + '/update_success.xml')
|
92
|
-
|
93
|
-
obj = instance
|
94
|
-
set_response(r)
|
95
|
-
obj.valid_account? # 1st request
|
96
72
|
|
73
|
+
def test_request_waits_necessary_time_between_requests
|
74
|
+
@delicious.expects(:make_request).times(4).returns(load_fixture('/net_response_success.yml'))
|
75
|
+
@delicious.valid_account? # 1st request
|
97
76
|
3.times do |time|
|
98
|
-
lr =
|
99
|
-
|
100
|
-
|
101
|
-
nr = obj.instance_variable_get(:@last_request)
|
77
|
+
lr = @delicious.instance_variable_get(:@last_request)
|
78
|
+
@delicious.valid_account? # N request
|
79
|
+
nr = @delicious.instance_variable_get(:@last_request)
|
102
80
|
assert((nr - lr) > WWW::Delicious::SECONDS_BEFORE_NEW_REQUEST)
|
103
81
|
end
|
104
82
|
end
|
105
|
-
|
83
|
+
|
84
|
+
|
85
|
+
def test_valid_account
|
86
|
+
@delicious.expects(:make_request).once.returns(load_fixture('/net_response_success.yml'))
|
87
|
+
assert(@delicious.valid_account?)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_invalid_account
|
91
|
+
@delicious.expects(:make_request).once.returns(load_fixture('/net_response_invalid_account.yml'))
|
92
|
+
assert(!@delicious.valid_account?)
|
93
|
+
end
|
94
|
+
|
106
95
|
|
107
96
|
# =========================================================================
|
108
97
|
# Update
|
109
98
|
# =========================================================================
|
110
99
|
|
111
100
|
def test_update
|
112
|
-
|
113
|
-
|
114
|
-
assert_nothing_raised() { results = instance.update() }
|
115
|
-
assert_equal(results, Time.parse("2008-03-12T08:41:20Z"))
|
101
|
+
@delicious.expects(:request).once.returns(mock_response('/response/update.xml'))
|
102
|
+
assert_equal(@delicious.update, Time.parse("2008-08-02T11:55:35Z"))
|
116
103
|
end
|
117
104
|
|
118
105
|
def test_update_raises_without_update_root_node
|
119
|
-
|
120
|
-
|
121
|
-
|
106
|
+
@delicious.expects(:request).once.returns(mock_response('/response/bundles_all.xml'))
|
107
|
+
error = assert_raise(WWW::Delicious::ResponseError) do
|
108
|
+
@delicious.update
|
122
109
|
end
|
123
|
-
assert_match(/`update`/,
|
110
|
+
assert_match(/`update`/, error.message)
|
124
111
|
end
|
125
|
-
|
112
|
+
|
113
|
+
def test_update_delicious1
|
114
|
+
@delicious.expects(:request).once.returns(mock_response('/response/update.delicious1.xml'))
|
115
|
+
assert_equal(@delicious.update, Time.parse("2008-03-12T08:41:20Z"))
|
116
|
+
end
|
117
|
+
|
126
118
|
|
127
119
|
# =========================================================================
|
128
120
|
# Bundles
|
129
121
|
# =========================================================================
|
130
|
-
# Test all bundle calls and related methods.
|
131
|
-
# * bundles_all
|
132
|
-
# * bundles_set
|
133
|
-
# * bundles_delete
|
134
122
|
|
135
123
|
def test_bundles_all
|
136
|
-
|
137
|
-
|
124
|
+
@delicious.expects(:request).once.returns(mock_response('/response/bundles_all.xml'))
|
125
|
+
expected = [ ['music', %w(ipod mp3 music)], ['pc', %w(computer software hardware)] ]
|
138
126
|
|
139
|
-
|
127
|
+
results = @delicious.bundles_all
|
140
128
|
assert_instance_of(Array, results)
|
141
129
|
assert_equal(2, results.length)
|
142
130
|
|
143
|
-
expected = [
|
144
|
-
['music', %w(ipod mp3 music)],
|
145
|
-
['pc', %w(computer software hardware)],
|
146
|
-
]
|
147
|
-
|
148
131
|
results.each_with_index do |bundle, index|
|
149
132
|
assert_instance_of(WWW::Delicious::Bundle, bundle)
|
150
133
|
name, tags = expected[index]
|
@@ -154,71 +137,69 @@ class DeliciousTest < Test::Unit::TestCase
|
|
154
137
|
end
|
155
138
|
|
156
139
|
def test_bundles_all_empty
|
157
|
-
|
158
|
-
results =
|
159
|
-
assert_nothing_raised() { results = instance.bundles_all() }
|
140
|
+
@delicious.expects(:request).once.returns(mock_response('/response/bundles_all_empty.xml'))
|
141
|
+
results = @delicious.bundles_all
|
160
142
|
assert_instance_of(Array, results)
|
161
143
|
assert_equal(0, results.length)
|
162
144
|
end
|
163
145
|
|
164
146
|
def test_bundles_all_raises_without_bundles_root_node
|
165
|
-
|
166
|
-
|
167
|
-
|
147
|
+
@delicious.expects(:request).once.returns(mock_response('/response/update.xml'))
|
148
|
+
error = assert_raise(WWW::Delicious::ResponseError) do
|
149
|
+
@delicious.bundles_all
|
168
150
|
end
|
169
|
-
assert_match(/`bundles`/,
|
151
|
+
assert_match(/`bundles`/, error.message)
|
170
152
|
end
|
171
|
-
|
172
|
-
|
153
|
+
|
154
|
+
|
173
155
|
def test_bundles_set
|
174
|
-
|
175
|
-
|
156
|
+
@delicious.expects(:request).once.returns(mock_response('/response/bundles_set.xml'))
|
157
|
+
assert(@delicious.bundles_set('name', %w(foo bar)))
|
176
158
|
end
|
177
159
|
|
178
|
-
def
|
179
|
-
|
180
|
-
|
181
|
-
|
160
|
+
def test_bundles_set_raises_with_response_error
|
161
|
+
@delicious.expects(:request).once.returns(mock_response('/response/bundles_set_error.xml'))
|
162
|
+
error = assert_raise(WWW::Delicious::Error) do
|
163
|
+
@delicious.bundles_set('name', %w(foo bar))
|
182
164
|
end
|
183
|
-
assert_match(
|
165
|
+
assert_match(/you must supply a bundle name/, error.message)
|
184
166
|
end
|
185
|
-
|
167
|
+
|
168
|
+
def test_bundles_set_raises_without_result_root_node
|
169
|
+
@delicious.expects(:request).once.returns(mock_response('/response/update.xml'))
|
170
|
+
error = assert_raise(WWW::Delicious::ResponseError) do
|
171
|
+
@delicious.bundles_set('name', %w(foo bar))
|
172
|
+
end
|
173
|
+
assert_match(/`result`/, error.message)
|
174
|
+
end
|
175
|
+
|
186
176
|
|
187
177
|
def test_bundles_delete
|
188
|
-
|
189
|
-
|
178
|
+
@delicious.expects(:request).once.returns(mock_response('/response/bundles_delete.xml'))
|
179
|
+
assert(@delicious.bundles_delete('name'))
|
190
180
|
end
|
191
181
|
|
192
182
|
def test_bundles_delete_raises_without_result_root_node
|
193
|
-
|
194
|
-
|
195
|
-
|
183
|
+
@delicious.expects(:request).once.returns(mock_response('/response/update.xml'))
|
184
|
+
error = assert_raise(WWW::Delicious::ResponseError) do
|
185
|
+
@delicious.bundles_delete('name')
|
196
186
|
end
|
197
|
-
assert_match(/`result`/,
|
187
|
+
assert_match(/`result`/, error.message)
|
198
188
|
end
|
199
|
-
|
189
|
+
|
200
190
|
|
201
191
|
# =========================================================================
|
202
192
|
# Tags
|
203
193
|
# =========================================================================
|
204
|
-
# Test all tag calls and related methods.
|
205
|
-
# * tags_get
|
206
|
-
# * tags_rename
|
207
194
|
|
208
|
-
|
209
195
|
def test_tags_get
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
196
|
+
@delicious.expects(:request).once.returns(mock_response('/response/tags_get.xml'))
|
197
|
+
expected = [ ['activedesktop', 1], ['business', 14] ]
|
198
|
+
|
199
|
+
results = @delicious.tags_get
|
214
200
|
assert_instance_of(Array, results)
|
215
201
|
assert_equal(2, results.length)
|
216
202
|
|
217
|
-
expected = [
|
218
|
-
['activedesktop', 1],
|
219
|
-
['business', 14],
|
220
|
-
]
|
221
|
-
|
222
203
|
results.each_with_index do |tag, index|
|
223
204
|
assert_instance_of(WWW::Delicious::Tag, tag)
|
224
205
|
name, count = expected[index]
|
@@ -226,195 +207,162 @@ class DeliciousTest < Test::Unit::TestCase
|
|
226
207
|
assert_equal(count, tag.count)
|
227
208
|
end
|
228
209
|
end
|
229
|
-
|
210
|
+
|
230
211
|
def test_tags_get_empty
|
231
|
-
|
232
|
-
results =
|
233
|
-
assert_nothing_raised() { results = instance.tags_get() }
|
212
|
+
@delicious.expects(:request).once.returns(mock_response('/response/tags_get_empty.xml'))
|
213
|
+
results = @delicious.tags_get
|
234
214
|
assert_instance_of(Array, results)
|
235
215
|
assert_equal(0, results.length)
|
236
216
|
end
|
237
217
|
|
238
218
|
def test_tags_get_raises_without_bundles_root_node
|
239
|
-
|
240
|
-
|
241
|
-
|
219
|
+
@delicious.expects(:request).once.returns(mock_response('/response/update.xml'))
|
220
|
+
error = assert_raise(WWW::Delicious::ResponseError) do
|
221
|
+
@delicious.tags_get
|
242
222
|
end
|
243
|
-
assert_match(/`tags`/,
|
223
|
+
assert_match(/`tags`/, error.message)
|
244
224
|
end
|
245
|
-
|
225
|
+
|
246
226
|
|
247
227
|
def test_tags_rename
|
248
|
-
|
249
|
-
|
228
|
+
@delicious.expects(:request).once.returns(mock_response('/response/tags_rename.xml'))
|
229
|
+
assert(@delicious.tags_rename('old', 'new'))
|
250
230
|
end
|
251
231
|
|
252
232
|
def test_tags_rename_raises_without_result_root_node
|
253
|
-
|
254
|
-
|
255
|
-
|
233
|
+
@delicious.expects(:request).once.returns(mock_response('/response/update.xml'))
|
234
|
+
error = assert_raise(WWW::Delicious::ResponseError) do
|
235
|
+
@delicious.tags_rename('foo', 'bar')
|
256
236
|
end
|
257
|
-
assert_match(/`result`/,
|
237
|
+
assert_match(/`result`/, error.message)
|
258
238
|
end
|
259
|
-
|
239
|
+
|
260
240
|
|
261
241
|
# =========================================================================
|
262
|
-
#
|
263
|
-
# TODO: as soon as a full offline test system is ready,
|
264
|
-
# remove protected methods tests .
|
242
|
+
# Posts
|
265
243
|
# =========================================================================
|
266
244
|
|
267
245
|
def test_posts_get
|
246
|
+
@delicious.expects(:request).once.returns(mock_response('/response/posts_get.xml'))
|
247
|
+
results = @delicious.posts_get
|
248
|
+
assert_instance_of(Array, results)
|
249
|
+
assert_equal(3, results.length)
|
250
|
+
assert_equal('New to Git? — GitHub', results.first.title)
|
251
|
+
assert_equal('.c( whytheluckystiff )o. -- The Fully Upturned Bin', results.last.title)
|
252
|
+
end
|
253
|
+
|
254
|
+
def test_posts_get_raises_without_posts_root_node
|
255
|
+
@delicious.expects(:request).once.returns(mock_response('/response/update.xml'))
|
256
|
+
error = assert_raise(WWW::Delicious::ResponseError) do
|
257
|
+
@delicious.posts_get
|
258
|
+
end
|
259
|
+
assert_match(/`posts`/, error.message)
|
268
260
|
end
|
269
|
-
|
270
261
|
|
271
|
-
# =========================================================================
|
272
|
-
# These tests check posts_recent call and all related methods.
|
273
|
-
# TODO: as soon as a full offline test system is ready,
|
274
|
-
# remove protected methods tests .
|
275
|
-
# =========================================================================
|
276
262
|
|
277
263
|
def test_posts_recent
|
264
|
+
@delicious.expects(:request).once.returns(mock_response('/response/posts_recent.xml'))
|
265
|
+
results = @delicious.posts_recent
|
266
|
+
assert_instance_of(Array, results)
|
267
|
+
assert_equal(15, results.length)
|
268
|
+
assert_equal('New to Git? — GitHub', results.first.title)
|
269
|
+
assert_equal('RichText | Lightview for modal dialogs on Rails', results.last.title)
|
278
270
|
end
|
279
271
|
|
272
|
+
def test_posts_recent_raises_without_posts_root_node
|
273
|
+
@delicious.expects(:request).once.returns(mock_response('/response/update.xml'))
|
274
|
+
error = assert_raise(WWW::Delicious::ResponseError) do
|
275
|
+
@delicious.posts_recent
|
276
|
+
end
|
277
|
+
assert_match(/`posts`/, error.message)
|
278
|
+
end
|
280
279
|
|
281
|
-
# =========================================================================
|
282
|
-
# These tests check posts_all call and all related methods.
|
283
|
-
# TODO: as soon as a full offline test system is ready,
|
284
|
-
# remove protected methods tests .
|
285
|
-
# =========================================================================
|
286
280
|
|
287
281
|
def test_posts_all
|
282
|
+
@delicious.expects(:request).once.returns(mock_response('/response/posts_all.xml'))
|
283
|
+
results = @delicious.posts_all
|
284
|
+
assert_instance_of(Array, results)
|
285
|
+
assert_equal(8, results.length)
|
286
|
+
assert_equal('New to Git? — GitHub', results.first.title)
|
287
|
+
assert_equal('ASP 101 - Object Oriented ASP: Using Classes in Classic ASP', results.last.title)
|
288
288
|
end
|
289
289
|
|
290
|
+
def test_posts_all_raises_without_posts_root_node
|
291
|
+
@delicious.expects(:request).once.returns(mock_response('/response/update.xml'))
|
292
|
+
error = assert_raise(WWW::Delicious::ResponseError) do
|
293
|
+
@delicious.posts_all
|
294
|
+
end
|
295
|
+
assert_match(/`posts`/, error.message)
|
296
|
+
end
|
290
297
|
|
291
|
-
# =========================================================================
|
292
|
-
# These tests check posts_dates call and all related methods.
|
293
|
-
# =========================================================================
|
294
298
|
|
295
299
|
def test_posts_dates
|
296
|
-
|
297
|
-
results =
|
298
|
-
assert_nothing_raised() { results = instance.posts_dates() }
|
300
|
+
@delicious.expects(:request).once.returns(mock_response('/response/posts_dates.xml'))
|
301
|
+
results = @delicious.posts_dates
|
299
302
|
assert_instance_of(Hash, results)
|
303
|
+
assert_equal(10, results.length)
|
300
304
|
end
|
301
305
|
|
302
306
|
def test_posts_dates_raises_without_dates_root_node
|
303
|
-
|
304
|
-
|
305
|
-
|
307
|
+
@delicious.expects(:request).once.returns(mock_response('/response/update.xml'))
|
308
|
+
error = assert_raise(WWW::Delicious::ResponseError) do
|
309
|
+
@delicious.posts_dates
|
306
310
|
end
|
307
|
-
assert_match(/`dates`/,
|
311
|
+
assert_match(/`dates`/, error.message)
|
308
312
|
end
|
309
313
|
|
310
|
-
# =========================================================================
|
311
|
-
# These tests check posts_add call and all related methods.
|
312
|
-
# =========================================================================
|
313
314
|
|
314
315
|
def test_posts_add
|
315
316
|
params = {:url => 'http://localhost', :title => 'Just a test'}
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
set_response(File.read(TESTCASE_PATH + '/posts_add_success.xml'))
|
321
|
-
assert_nothing_raised() { instance.posts_add(params) }
|
317
|
+
@delicious.expects(:request).times(2).returns(mock_response('/response/posts_add.xml'))
|
318
|
+
assert(@delicious.posts_add(WWW::Delicious::Post.new(params)))
|
319
|
+
assert(@delicious.posts_add(params))
|
322
320
|
end
|
323
|
-
|
324
321
|
|
325
|
-
# =========================================================================
|
326
|
-
# These tests check posts_delete call and all related methods.
|
327
|
-
# =========================================================================
|
328
322
|
|
329
323
|
def test_posts_delete
|
330
|
-
|
331
|
-
|
324
|
+
@delicious.expects(:request).once.returns(mock_response('/response/posts_delete.xml'))
|
325
|
+
assert(@delicious.posts_delete('test'))
|
332
326
|
end
|
333
327
|
|
334
328
|
def test_posts_delete_raises_without_result_root_node
|
335
|
-
|
336
|
-
|
337
|
-
|
329
|
+
@delicious.expects(:request).once.returns(mock_response('/response/update.xml'))
|
330
|
+
error = assert_raise(WWW::Delicious::ResponseError) do
|
331
|
+
@delicious.posts_delete('test')
|
338
332
|
end
|
339
|
-
assert_match(/`result`/,
|
333
|
+
assert_match(/`result`/, error.message)
|
340
334
|
end
|
341
|
-
|
342
335
|
|
343
336
|
|
344
|
-
def test_prepare_posts_params
|
345
|
-
tag = 'foo'
|
346
|
-
count = 30
|
347
|
-
url = 'http://localhost'
|
348
|
-
dt = Time.now
|
349
|
-
|
350
|
-
params = { :tag => tag, :url => url, :dt => dt, :count => count }
|
351
|
-
results = instance.send(:prepare_posts_params, params, [:tag, :count, :url, :dt])
|
352
|
-
|
353
|
-
assert_kind_of(WWW::Delicious::Tag, results[:tag])
|
354
|
-
assert_equal(tag, results[:tag].to_s)
|
355
|
-
assert_equal(count, results[:count])
|
356
|
-
assert_equal(URI.parse(url), results[:url])
|
357
|
-
assert_equal(dt.iso8601(), results[:dt])
|
358
|
-
end
|
359
337
|
|
360
|
-
|
361
|
-
['foo', %w(foo bar)].each do |params|
|
362
|
-
exception = assert_raise(ArgumentError) do
|
363
|
-
instance.send(:prepare_posts_params, params)
|
364
|
-
end
|
365
|
-
assert_match(/`Hash`/, exception.message)
|
366
|
-
end
|
367
|
-
end
|
338
|
+
protected
|
368
339
|
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
instance.send(:prepare_posts_params, params, [:tag])
|
340
|
+
# returns a stub instance
|
341
|
+
def instance(options = {}, &block)
|
342
|
+
WWW::Delicious.new(TEST_USERNAME, TEST_PASSWORD, options, &block)
|
373
343
|
end
|
374
|
-
assert_match(/`foo`/, exception.message)
|
375
|
-
end
|
376
344
|
|
377
|
-
|
378
|
-
|
379
|
-
response = instance.send(:parse_posts_response,
|
380
|
-
File.read(TESTCASE_PATH + '/posts_success.xml'))
|
381
|
-
assert_instance_of(Array, response)
|
382
|
-
assert_equal(1, response.length)
|
383
|
-
|
384
|
-
results = [
|
385
|
-
['http://stacktrace.it/articoli/2008/03/i-7-peccati-capitali-del-recruitment-di-hacker/', 'Stacktrace.it: I 7 peccati capitali del recruitment di hacker'],
|
386
|
-
]
|
387
|
-
|
388
|
-
response.each_with_index do |post, index|
|
389
|
-
assert_instance_of(WWW::Delicious::Post, post)
|
390
|
-
url, title = results[index]
|
391
|
-
assert_equal(URI.parse(url), post.url)
|
392
|
-
assert_equal(title, post.title)
|
345
|
+
def load_testcase(file)
|
346
|
+
File.read(TESTCASES_PATH + file)
|
393
347
|
end
|
394
|
-
end
|
395
|
-
|
396
|
-
def test_parse_posts_response_empty
|
397
|
-
response = instance.send(:parse_posts_response,
|
398
|
-
File.read(TESTCASE_PATH + '/posts_success_empty.xml'))
|
399
|
-
assert_instance_of(Array, response)
|
400
|
-
assert_equal(0, response.length)
|
401
|
-
end
|
402
|
-
|
403
|
-
def test_parse_posts_response_without_bundles_root_node
|
404
|
-
_test_parse_invalid_node(:parse_posts_response, /`posts`/)
|
405
|
-
end
|
406
348
|
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
349
|
+
def load_fixture(file)
|
350
|
+
YAML.load(File.read(FIXTURES_PATH + file))
|
351
|
+
end
|
352
|
+
|
353
|
+
def mock_response(file_or_content)
|
354
|
+
content = case
|
355
|
+
when file_or_content =~ /\.xml$/
|
356
|
+
load_testcase(file_or_content)
|
357
|
+
when file_or_content =~ /\.yml$/
|
358
|
+
load_fixture(file_or_content)
|
359
|
+
else
|
360
|
+
file_or_content.to_s
|
361
|
+
end
|
362
|
+
|
363
|
+
response = mock()
|
364
|
+
response.expects(:body).at_least(1).returns(content)
|
365
|
+
response
|
416
366
|
end
|
417
|
-
assert_match(match, exception.message)
|
418
|
-
end
|
419
367
|
|
420
368
|
end
|