jugend-httparty 0.5.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/.gitignore +7 -0
  2. data/History +209 -0
  3. data/MIT-LICENSE +20 -0
  4. data/Manifest +47 -0
  5. data/README.rdoc +54 -0
  6. data/Rakefile +80 -0
  7. data/VERSION +1 -0
  8. data/bin/httparty +108 -0
  9. data/cucumber.yml +1 -0
  10. data/examples/aaws.rb +32 -0
  11. data/examples/basic.rb +11 -0
  12. data/examples/custom_parsers.rb +67 -0
  13. data/examples/delicious.rb +37 -0
  14. data/examples/google.rb +16 -0
  15. data/examples/rubyurl.rb +14 -0
  16. data/examples/twitter.rb +31 -0
  17. data/examples/whoismyrep.rb +10 -0
  18. data/features/basic_authentication.feature +20 -0
  19. data/features/command_line.feature +7 -0
  20. data/features/deals_with_http_error_codes.feature +26 -0
  21. data/features/handles_multiple_formats.feature +34 -0
  22. data/features/steps/env.rb +23 -0
  23. data/features/steps/httparty_response_steps.rb +26 -0
  24. data/features/steps/httparty_steps.rb +27 -0
  25. data/features/steps/mongrel_helper.rb +78 -0
  26. data/features/steps/remote_service_steps.rb +61 -0
  27. data/features/supports_redirection.feature +22 -0
  28. data/features/supports_timeout_option.feature +13 -0
  29. data/jugend-httparty.gemspec +127 -0
  30. data/lib/httparty/cookie_hash.rb +22 -0
  31. data/lib/httparty/core_extensions.rb +31 -0
  32. data/lib/httparty/exceptions.rb +26 -0
  33. data/lib/httparty/module_inheritable_attributes.rb +25 -0
  34. data/lib/httparty/parser.rb +141 -0
  35. data/lib/httparty/request.rb +206 -0
  36. data/lib/httparty/response.rb +62 -0
  37. data/lib/httparty.rb +343 -0
  38. data/spec/fixtures/delicious.xml +23 -0
  39. data/spec/fixtures/empty.xml +0 -0
  40. data/spec/fixtures/google.html +3 -0
  41. data/spec/fixtures/twitter.json +1 -0
  42. data/spec/fixtures/twitter.xml +403 -0
  43. data/spec/fixtures/undefined_method_add_node_for_nil.xml +2 -0
  44. data/spec/httparty/cookie_hash_spec.rb +71 -0
  45. data/spec/httparty/parser_spec.rb +154 -0
  46. data/spec/httparty/request_spec.rb +415 -0
  47. data/spec/httparty/response_spec.rb +83 -0
  48. data/spec/httparty_spec.rb +514 -0
  49. data/spec/spec.opts +3 -0
  50. data/spec/spec_helper.rb +19 -0
  51. data/spec/support/stub_response.rb +30 -0
  52. data/website/css/common.css +47 -0
  53. data/website/index.html +73 -0
  54. metadata +209 -0
@@ -0,0 +1,403 @@
1
+ <statuses type="array">
2
+ <status>
3
+ <created_at>Sun Dec 07 00:36:16 +0000 2008</created_at>
4
+ <id>1042729116</id>
5
+ <text>@sebbo Outlook not so good</text>
6
+ <source>web</source>
7
+ <truncated>false</truncated>
8
+ <in_reply_to_status_id>1042716367</in_reply_to_status_id>
9
+ <in_reply_to_user_id>2989541</in_reply_to_user_id>
10
+ <favorited>false</favorited>
11
+ <user>
12
+ <id>17656026</id>
13
+ <name>Magic 8 Bot</name>
14
+ <screen_name>magic8bot</screen_name>
15
+ <description>ask me a question</description>
16
+ <location></location>
17
+ <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/65565851/8ball_large_normal.jpg</profile_image_url>
18
+ <url></url>
19
+ <protected>false</protected>
20
+ <followers_count>90</followers_count>
21
+ </user>
22
+ </status><status>
23
+ <created_at>Sun Dec 07 00:36:14 +0000 2008</created_at>
24
+ <id>1042729115</id>
25
+ <text>Azdel Slade :friends from midian city http://bloghud.com/id/27312</text>
26
+ <source>web</source>
27
+ <truncated>false</truncated>
28
+ <in_reply_to_status_id />
29
+ <in_reply_to_user_id />
30
+ <favorited>false</favorited>
31
+ <user>
32
+ <id>801094</id>
33
+ <name>BlogHUD</name>
34
+ <screen_name>bloghud</screen_name>
35
+ <description />
36
+ <location />
37
+ <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/25235272/bloghud_twitter_normal.jpg</profile_image_url>
38
+ <url />
39
+ <protected>false</protected>
40
+ <followers_count>313</followers_count>
41
+ </user>
42
+ </status><status>
43
+ <created_at>Sun Dec 07 00:36:14 +0000 2008</created_at>
44
+ <id>1042729114</id>
45
+ <text>Reading: &quot;The Reckoning - Debt Watchdogs - Tamed or Caught Napping? - Series - NYTimes.com&quot; ( http://tinyurl.com/5754s6 )</text>
46
+ <source>twitthat</source>
47
+ <truncated>false</truncated>
48
+ <in_reply_to_status_id />
49
+ <in_reply_to_user_id />
50
+ <favorited>false</favorited>
51
+ <user>
52
+ <id>3512101</id>
53
+ <name>bill</name>
54
+ <screen_name>niubi</screen_name>
55
+ <description>in beijing learning socialism 2 prepare 4 return 2 us</description>
56
+ <location>beijing</location>
57
+ <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/53292616/realtwitterers_normal.jpg</profile_image_url>
58
+ <url></url>
59
+ <protected>false</protected>
60
+ <followers_count>710</followers_count>
61
+ </user>
62
+ </status><status>
63
+ <created_at>Sun Dec 07 00:36:14 +0000 2008</created_at>
64
+ <id>1042729113</id>
65
+ <text>Fianlly done and headed home!</text>
66
+ <source>sms</source>
67
+ <truncated>false</truncated>
68
+ <in_reply_to_status_id />
69
+ <in_reply_to_user_id />
70
+ <favorited>false</favorited>
71
+ <user>
72
+ <id>13186842</id>
73
+ <name>Okthirddayfan</name>
74
+ <screen_name>Okthirddayfan</screen_name>
75
+ <description></description>
76
+ <location>Oklahoma!</location>
77
+ <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/61414367/mecropped_normal.jpg</profile_image_url>
78
+ <url>http://thirddaypix.blogspot.com/</url>
79
+ <protected>false</protected>
80
+ <followers_count>68</followers_count>
81
+ </user>
82
+ </status><status>
83
+ <created_at>Sun Dec 07 00:36:16 +0000 2008</created_at>
84
+ <id>1042729112</id>
85
+ <text>Adobe Flashplayer 10 and Debug versions: http://www.adobe.com/support/flashplayer/downloads.html</text>
86
+ <source>toro</source>
87
+ <truncated>false</truncated>
88
+ <in_reply_to_status_id />
89
+ <in_reply_to_user_id />
90
+ <favorited>false</favorited>
91
+ <user>
92
+ <id>15243380</id>
93
+ <name>cbrueggenolte</name>
94
+ <screen_name>cbrueggenolte</screen_name>
95
+ <description>27, Male, Mac Geek, Developer Java &amp;amp; Flex &amp;amp; Air</description>
96
+ <location>Aachen</location>
97
+ <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/55929263/214508011845f026bfd407c_normal.jpg</profile_image_url>
98
+ <url>http://my.opera.com/carstenbrueggenolte</url>
99
+ <protected>false</protected>
100
+ <followers_count>16</followers_count>
101
+ </user>
102
+ </status><status>
103
+ <created_at>Sun Dec 07 00:36:14 +0000 2008</created_at>
104
+ <id>1042729111</id>
105
+ <text>Done and done.</text>
106
+ <source>twitterrific</source>
107
+ <truncated>false</truncated>
108
+ <in_reply_to_status_id />
109
+ <in_reply_to_user_id />
110
+ <favorited>false</favorited>
111
+ <user>
112
+ <id>10978752</id>
113
+ <name>Sergey Safonov</name>
114
+ <screen_name>iron_Lung</screen_name>
115
+ <description>I have my fingers in many pies.</description>
116
+ <location>Moscow</location>
117
+ <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/57841057/eat38_normal.gif</profile_image_url>
118
+ <url>http://www.flickr.com/photos/iron_Lung</url>
119
+ <protected>false</protected>
120
+ <followers_count>11</followers_count>
121
+ </user>
122
+ </status><status>
123
+ <created_at>Sun Dec 07 00:36:14 +0000 2008</created_at>
124
+ <id>1042729110</id>
125
+ <text>Veja a tabela de preços do Acquaplay da Tecnisa aqui:http://tinyurl.com/acquaplaypreco</text>
126
+ <source>web</source>
127
+ <truncated>false</truncated>
128
+ <in_reply_to_status_id />
129
+ <in_reply_to_user_id />
130
+ <favorited>false</favorited>
131
+ <user>
132
+ <id>13735402</id>
133
+ <name>Tecnisa S.A</name>
134
+ <screen_name>Tecnisa</screen_name>
135
+ <description>Mais construtora por m2</description>
136
+ <location>Faria Lima, 3144 - SP</location>
137
+ <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/56572222/logo_normal.jpg</profile_image_url>
138
+ <url>http://www.tecnisa.com.br</url>
139
+ <protected>false</protected>
140
+ <followers_count>77</followers_count>
141
+ </user>
142
+ </status><status>
143
+ <created_at>Sun Dec 07 00:36:16 +0000 2008</created_at>
144
+ <id>1042729108</id>
145
+ <text>devin harris has the flu. always have the memory of jordan scoring 50 on the knicks at the garden with the flu</text>
146
+ <source>web</source>
147
+ <truncated>false</truncated>
148
+ <in_reply_to_status_id />
149
+ <in_reply_to_user_id />
150
+ <favorited>false</favorited>
151
+ <user>
152
+ <id>17930773</id>
153
+ <name>24 Seconds to Shoot</name>
154
+ <screen_name>NBA24sts</screen_name>
155
+ <description>NBA handicapping insight and analysis.</description>
156
+ <location>las vegas</location>
157
+ <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/66593862/fresno_normal.jpg</profile_image_url>
158
+ <url></url>
159
+ <protected>false</protected>
160
+ <followers_count>1</followers_count>
161
+ </user>
162
+ </status><status>
163
+ <created_at>Sun Dec 07 00:36:16 +0000 2008</created_at>
164
+ <id>1042729105</id>
165
+ <text>At Brandon and Shannon's holiday party..</text>
166
+ <source>twitterberry</source>
167
+ <truncated>false</truncated>
168
+ <in_reply_to_status_id />
169
+ <in_reply_to_user_id />
170
+ <favorited>false</favorited>
171
+ <user>
172
+ <id>5388602</id>
173
+ <name>Mike J. (Telligent)</name>
174
+ <screen_name>mjamrst</screen_name>
175
+ <description>Video Game Account Manager</description>
176
+ <location>Palo Alto, CA</location>
177
+ <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/66375174/Thanksgiving_11272008-048_normal.jpg</profile_image_url>
178
+ <url>http://www.telligent.com</url>
179
+ <protected>false</protected>
180
+ <followers_count>225</followers_count>
181
+ </user>
182
+ </status><status>
183
+ <created_at>Sun Dec 07 00:36:13 +0000 2008</created_at>
184
+ <id>1042729104</id>
185
+ <text>Xinhua: Forty percent of Australian PM office' staff quit : CANBERRA, Dec. 7 (Xinhua) -- Only.. http://tinyurl.com/5gwotd</text>
186
+ <source>twitterfeed</source>
187
+ <truncated>false</truncated>
188
+ <in_reply_to_status_id />
189
+ <in_reply_to_user_id />
190
+ <favorited>false</favorited>
191
+ <user>
192
+ <id>11566502</id>
193
+ <name>Headline News</name>
194
+ <screen_name>headlinenews</screen_name>
195
+ <description></description>
196
+ <location></location>
197
+ <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/41784602/1890_wires_normal.jpg</profile_image_url>
198
+ <url></url>
199
+ <protected>false</protected>
200
+ <followers_count>575</followers_count>
201
+ </user>
202
+ </status><status>
203
+ <created_at>Sun Dec 07 00:36:13 +0000 2008</created_at>
204
+ <id>1042729101</id>
205
+ <text>@hilarycassman soo funnny</text>
206
+ <source>sms</source>
207
+ <truncated>false</truncated>
208
+ <in_reply_to_status_id>1042725825</in_reply_to_status_id>
209
+ <in_reply_to_user_id>17644455</in_reply_to_user_id>
210
+ <favorited>false</favorited>
211
+ <user>
212
+ <id>17887548</id>
213
+ <name>katieballss</name>
214
+ <screen_name>katieballss</screen_name>
215
+ <description></description>
216
+ <location></location>
217
+ <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/66523737/th_Photo87_normal.jpg</profile_image_url>
218
+ <url>http://www.myspace.com/xxpeachxx101</url>
219
+ <protected>false</protected>
220
+ <followers_count>23</followers_count>
221
+ </user>
222
+ </status><status>
223
+ <created_at>Sun Dec 07 00:36:13 +0000 2008</created_at>
224
+ <id>1042729100</id>
225
+ <text>d'ora in poi, oltre al ferragosto, odiera' anche il natale e tutto il mese che ci gira intorno.. =.=''</text>
226
+ <source>mobile</source>
227
+ <truncated>false</truncated>
228
+ <in_reply_to_status_id />
229
+ <in_reply_to_user_id />
230
+ <favorited>false</favorited>
231
+ <user>
232
+ <id>9719482</id>
233
+ <name>trotto</name>
234
+ <screen_name>trotto</screen_name>
235
+ <description>sociologo di formazione... uno dei tanti attivisti! :)</description>
236
+ <location>Fano - Italy</location>
237
+ <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/55603933/mybob-calimetux-1526_normal.png</profile_image_url>
238
+ <url>http://trotto1308.netsons.org/wordpress/</url>
239
+ <protected>false</protected>
240
+ <followers_count>98</followers_count>
241
+ </user>
242
+ </status><status>
243
+ <created_at>Sun Dec 07 00:36:13 +0000 2008</created_at>
244
+ <id>1042729099</id>
245
+ <text>Came across an ad on another site with a redneck looking santa... said &quot;Bust Santa's zit and win a free ipod.&quot; Umm... disturbing much?</text>
246
+ <source>web</source>
247
+ <truncated>false</truncated>
248
+ <in_reply_to_status_id />
249
+ <in_reply_to_user_id />
250
+ <favorited>false</favorited>
251
+ <user>
252
+ <id>9937182</id>
253
+ <name>froggybluesock</name>
254
+ <screen_name>froggybluesock</screen_name>
255
+ <description></description>
256
+ <location>Indiana</location>
257
+ <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/35393032/about_me_normal.jpg</profile_image_url>
258
+ <url>http://www.footprintsonthemoon.com</url>
259
+ <protected>false</protected>
260
+ <followers_count>82</followers_count>
261
+ </user>
262
+ </status><status>
263
+ <created_at>Sun Dec 07 00:36:17 +0000 2008</created_at>
264
+ <id>1042729098</id>
265
+ <text>nothing</text>
266
+ <source>web</source>
267
+ <truncated>false</truncated>
268
+ <in_reply_to_status_id />
269
+ <in_reply_to_user_id />
270
+ <favorited>false</favorited>
271
+ <user>
272
+ <id>17932339</id>
273
+ <name>treblehook</name>
274
+ <screen_name>treblehook</screen_name>
275
+ <description />
276
+ <location />
277
+ <profile_image_url>http://static.twitter.com/images/default_profile_normal.png</profile_image_url>
278
+ <url />
279
+ <protected>false</protected>
280
+ <followers_count>0</followers_count>
281
+ </user>
282
+ </status><status>
283
+ <created_at>Sun Dec 07 00:36:13 +0000 2008</created_at>
284
+ <id>1042729095</id>
285
+ <text>Setting up my new Windows Live profile</text>
286
+ <source>web</source>
287
+ <truncated>false</truncated>
288
+ <in_reply_to_status_id />
289
+ <in_reply_to_user_id />
290
+ <favorited>false</favorited>
291
+ <user>
292
+ <id>17906075</id>
293
+ <name>Mark_Layton</name>
294
+ <screen_name>Mark_Layton</screen_name>
295
+ <description />
296
+ <location />
297
+ <profile_image_url>http://static.twitter.com/images/default_profile_normal.png</profile_image_url>
298
+ <url />
299
+ <protected>false</protected>
300
+ <followers_count>2</followers_count>
301
+ </user>
302
+ </status><status>
303
+ <created_at>Sun Dec 07 00:36:13 +0000 2008</created_at>
304
+ <id>1042729092</id>
305
+ <text>me voy a sobar, a ver si mañana estoy mejor, wenas noches a tod@s</text>
306
+ <source>web</source>
307
+ <truncated>false</truncated>
308
+ <in_reply_to_status_id />
309
+ <in_reply_to_user_id />
310
+ <favorited>false</favorited>
311
+ <user>
312
+ <id>14062655</id>
313
+ <name>tmaniak</name>
314
+ <screen_name>tmaniak</screen_name>
315
+ <description></description>
316
+ <location></location>
317
+ <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/51680481/BF-109_normal.jpg</profile_image_url>
318
+ <url>http://dhost.info/tmaniak</url>
319
+ <protected>false</protected>
320
+ <followers_count>10</followers_count>
321
+ </user>
322
+ </status><status>
323
+ <created_at>Sun Dec 07 00:36:14 +0000 2008</created_at>
324
+ <id>1042729090</id>
325
+ <text>バイト延長戦入りましたー 店長が遅刻ってどうなんだ。しかも何回も</text>
326
+ <source>natsuliphone</source>
327
+ <truncated>false</truncated>
328
+ <in_reply_to_status_id />
329
+ <in_reply_to_user_id />
330
+ <favorited>false</favorited>
331
+ <user>
332
+ <id>15618846</id>
333
+ <name>kabayaki</name>
334
+ <screen_name>kabayaki</screen_name>
335
+ <description>FPS(L4D、TF2、CS:S、BF)、TPS、RCG、マンガ、アニメ、デジモノが好きなとある学生</description>
336
+ <location>tokyo</location>
337
+ <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/57305902/184_normal.jpg</profile_image_url>
338
+ <url>http://kabayakiya.blog43.fc2.com/</url>
339
+ <protected>false</protected>
340
+ <followers_count>20</followers_count>
341
+ </user>
342
+ </status><status>
343
+ <created_at>Sun Dec 07 00:36:13 +0000 2008</created_at>
344
+ <id>1042729089</id>
345
+ <text>just drove to southern california and joy of children hugging grandparents made it all worthwhile. heading to imedia in la quinta tomorrow.</text>
346
+ <source>web</source>
347
+ <truncated>false</truncated>
348
+ <in_reply_to_status_id />
349
+ <in_reply_to_user_id />
350
+ <favorited>false</favorited>
351
+ <user>
352
+ <id>1630261</id>
353
+ <name>mark silva</name>
354
+ <screen_name>marksilva</screen_name>
355
+ <description>digital media http://realbranding.com Principal, Managing Director</description>
356
+ <location>often san francisco</location>
357
+ <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/29807902/silvasimpson3th_normal.jpg</profile_image_url>
358
+ <url>http://marksilva.com</url>
359
+ <protected>false</protected>
360
+ <followers_count>497</followers_count>
361
+ </user>
362
+ </status><status>
363
+ <created_at>Sun Dec 07 00:36:14 +0000 2008</created_at>
364
+ <id>1042729088</id>
365
+ <text>@wholefoods would love to have a juicebar in one of your cambridge or boston locations</text>
366
+ <source>web</source>
367
+ <truncated>false</truncated>
368
+ <in_reply_to_status_id>1041125103</in_reply_to_status_id>
369
+ <in_reply_to_user_id>15131310</in_reply_to_user_id>
370
+ <favorited>false</favorited>
371
+ <user>
372
+ <id>15856582</id>
373
+ <name>Maura McGovern</name>
374
+ <screen_name>mmcgovern</screen_name>
375
+ <description>photographer with a day job in venture capital; obsessed with design blogs, long walks, yoga, social networking, people watching. tea and music are essential!</description>
376
+ <location>Boston</location>
377
+ <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/66110383/DSCN1740_normal.JPG</profile_image_url>
378
+ <url>http://lefteyephotography.blogspot.com</url>
379
+ <protected>false</protected>
380
+ <followers_count>244</followers_count>
381
+ </user>
382
+ </status><status>
383
+ <created_at>Sun Dec 07 00:36:15 +0000 2008</created_at>
384
+ <id>1042729087</id>
385
+ <text>Going over the Advent lists.</text>
386
+ <source>web</source>
387
+ <truncated>false</truncated>
388
+ <in_reply_to_status_id />
389
+ <in_reply_to_user_id />
390
+ <favorited>false</favorited>
391
+ <user>
392
+ <id>17122107</id>
393
+ <name>gsusan</name>
394
+ <screen_name>gsusan</screen_name>
395
+ <description>US American writer/sister/daughter/aunt/woman from New England living in SoCal.</description>
396
+ <location>San Diego, CA USA</location>
397
+ <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/63951854/susan_ocracoke_normal.jpg</profile_image_url>
398
+ <url></url>
399
+ <protected>false</protected>
400
+ <followers_count>6</followers_count>
401
+ </user>
402
+ </status>
403
+ </statuses>
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <Entities total="0" results="0" page="1" page-size="25" href="https://s3-sandbox.parature.com/api/v1/5578/5633/Account" />
@@ -0,0 +1,71 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
2
+
3
+ describe HTTParty::CookieHash do
4
+ before(:each) do
5
+ @cookie_hash = HTTParty::CookieHash.new
6
+ end
7
+
8
+ describe "#add_cookies" do
9
+
10
+ describe "with a hash" do
11
+ it "should add new key/value pairs to the hash" do
12
+ @cookie_hash.add_cookies(:foo => "bar")
13
+ @cookie_hash.add_cookies(:rofl => "copter")
14
+ @cookie_hash.length.should eql(2)
15
+ end
16
+
17
+ it "should overwrite any existing key" do
18
+ @cookie_hash.add_cookies(:foo => "bar")
19
+ @cookie_hash.add_cookies(:foo => "copter")
20
+ @cookie_hash.length.should eql(1)
21
+ @cookie_hash[:foo].should eql("copter")
22
+ end
23
+ end
24
+
25
+ describe "with a string" do
26
+ it "should add new key/value pairs to the hash" do
27
+ @cookie_hash.add_cookies("first=one; second=two; third")
28
+ @cookie_hash[:first].should == 'one'
29
+ @cookie_hash[:second].should == 'two'
30
+ @cookie_hash[:third].should == nil
31
+ end
32
+
33
+ it "should overwrite any existing key" do
34
+ @cookie_hash[:foo] = 'bar'
35
+ @cookie_hash.add_cookies("foo=tar")
36
+ @cookie_hash.length.should eql(1)
37
+ @cookie_hash[:foo].should eql("tar")
38
+ end
39
+ end
40
+
41
+ describe 'with other class' do
42
+ it "should error" do
43
+ lambda {
44
+ @cookie_hash.add_cookies(Array.new)
45
+ }.should raise_error
46
+ end
47
+ end
48
+ end
49
+
50
+ # The regexen are required because Hashes aren't ordered, so a test against
51
+ # a hardcoded string was randomly failing.
52
+ describe "#to_cookie_string" do
53
+ before(:each) do
54
+ @cookie_hash.add_cookies(:foo => "bar")
55
+ @cookie_hash.add_cookies(:rofl => "copter")
56
+ @s = @cookie_hash.to_cookie_string
57
+ end
58
+
59
+ it "should format the key/value pairs, delimited by semi-colons" do
60
+ @s.should match(/foo=bar/)
61
+ @s.should match(/rofl=copter/)
62
+ @s.should match(/^\w+=\w+; \w+=\w+$/)
63
+ end
64
+
65
+ it "should not include client side only cookies" do
66
+ @cookie_hash.add_cookies(:path => "/")
67
+ @s = @cookie_hash.to_cookie_string
68
+ @s.should_not match(/path=\//)
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,154 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
+
3
+ class CustomParser < HTTParty::Parser; end
4
+
5
+ describe HTTParty::Parser do
6
+ describe ".SupportedFormats" do
7
+ it "returns a hash" do
8
+ HTTParty::Parser::SupportedFormats.should be_instance_of(Hash)
9
+ end
10
+ end
11
+
12
+ describe ".call" do
13
+ it "generates an HTTParty::Parser instance with the given body and format" do
14
+ HTTParty::Parser.should_receive(:new).with('body', :plain).and_return(stub(:parse => nil))
15
+ HTTParty::Parser.call('body', :plain)
16
+ end
17
+
18
+ it "calls #parse on the parser" do
19
+ parser = mock('Parser')
20
+ parser.should_receive(:parse)
21
+ HTTParty::Parser.stub(:new => parser)
22
+ parser = HTTParty::Parser.call('body', :plain)
23
+ end
24
+ end
25
+
26
+ describe ".formats" do
27
+ it "returns the SupportedFormats constant" do
28
+ HTTParty::Parser.formats.should == HTTParty::Parser::SupportedFormats
29
+ end
30
+
31
+ it "returns the SupportedFormats constant for subclasses" do
32
+ class MyParser < HTTParty::Parser
33
+ SupportedFormats = {"application/atom+xml" => :atom}
34
+ end
35
+ MyParser.formats.should == {"application/atom+xml" => :atom}
36
+ end
37
+ end
38
+
39
+ describe ".format_from_mimetype" do
40
+ it "returns a symbol representing the format mimetype" do
41
+ HTTParty::Parser.format_from_mimetype("text/plain").should == :plain
42
+ end
43
+
44
+ it "returns nil when the mimetype is not supported" do
45
+ HTTParty::Parser.format_from_mimetype("application/atom+xml").should be_nil
46
+ end
47
+ end
48
+
49
+ describe ".supported_formats" do
50
+ it "returns a unique set of supported formats represented by symbols" do
51
+ HTTParty::Parser.supported_formats.should == HTTParty::Parser::SupportedFormats.values.uniq
52
+ end
53
+ end
54
+
55
+ describe ".supports_format?" do
56
+ it "returns true for a supported format" do
57
+ HTTParty::Parser.stub(:supported_formats => [:json])
58
+ HTTParty::Parser.supports_format?(:json).should be_true
59
+ end
60
+
61
+ it "returns false for an unsupported format" do
62
+ HTTParty::Parser.stub(:supported_formats => [])
63
+ HTTParty::Parser.supports_format?(:json).should be_false
64
+ end
65
+ end
66
+
67
+ describe "#parse" do
68
+ before do
69
+ @parser = HTTParty::Parser.new('body', :json)
70
+ end
71
+
72
+ it "attempts to parse supported formats" do
73
+ @parser.stub(:supports_format? => true)
74
+ @parser.should_receive(:parse_supported_format)
75
+ @parser.parse
76
+ end
77
+
78
+ it "returns the unparsed body when the format is unsupported" do
79
+ @parser.stub(:supports_format? => false)
80
+ @parser.parse.should == @parser.body
81
+ end
82
+
83
+ it "returns nil for an empty body" do
84
+ @parser.stub(:body => '')
85
+ @parser.parse.should be_nil
86
+ end
87
+
88
+ it "returns nil for a nil body" do
89
+ @parser.stub(:body => nil)
90
+ @parser.parse.should be_nil
91
+ end
92
+ end
93
+
94
+ describe "#supports_format?" do
95
+ it "utilizes the class method to determine if the format is supported" do
96
+ HTTParty::Parser.should_receive(:supports_format?).with(:json)
97
+ parser = HTTParty::Parser.new('body', :json)
98
+ parser.send(:supports_format?)
99
+ end
100
+ end
101
+
102
+ describe "#parse_supported_format" do
103
+ it "calls the parser for the given format" do
104
+ parser = HTTParty::Parser.new('body', :json)
105
+ parser.should_receive(:json)
106
+ parser.send(:parse_supported_format)
107
+ end
108
+
109
+ context "when a parsing method does not exist for the given format" do
110
+ it "raises an exception" do
111
+ parser = HTTParty::Parser.new('body', :atom)
112
+ expect do
113
+ parser.send(:parse_supported_format)
114
+ end.to raise_error(NotImplementedError, "HTTParty::Parser has not implemented a parsing method for the :atom format.")
115
+ end
116
+
117
+ it "raises a useful exception message for subclasses" do
118
+ parser = CustomParser.new('body', :atom)
119
+ expect do
120
+ parser.send(:parse_supported_format)
121
+ end.to raise_error(NotImplementedError, "CustomParser has not implemented a parsing method for the :atom format.")
122
+ end
123
+ end
124
+ end
125
+
126
+ context "parsers" do
127
+ subject do
128
+ HTTParty::Parser.new('body', nil)
129
+ end
130
+
131
+ it "parses xml with Crack" do
132
+ Crack::XML.should_receive(:parse).with('body')
133
+ subject.send(:xml)
134
+ end
135
+
136
+ it "parses json with Crack" do
137
+ Crack::JSON.should_receive(:parse).with('body')
138
+ subject.send(:json)
139
+ end
140
+
141
+ it "parses yaml" do
142
+ YAML.should_receive(:load).with('body')
143
+ subject.send(:yaml)
144
+ end
145
+
146
+ it "parses html by simply returning the body" do
147
+ subject.send(:html).should == 'body'
148
+ end
149
+
150
+ it "parses plain text by simply returning the body" do
151
+ subject.send(:plain).should == 'body'
152
+ end
153
+ end
154
+ end