vulcan 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (260) hide show
  1. data/lib/vulcan/cli.rb +20 -10
  2. data/lib/vulcan/version.rb +1 -1
  3. data/server/Procfile +1 -1
  4. data/server/bin/web +10 -0
  5. data/server/lib/cloudant.coffee +20 -0
  6. data/server/lib/logger.coffee +17 -0
  7. data/server/lib/on.coffee +10 -0
  8. data/server/lib/spawner.coffee +65 -0
  9. data/server/node_modules/coffee-script/CNAME +1 -0
  10. data/server/node_modules/coffee-script/LICENSE +22 -0
  11. data/server/node_modules/coffee-script/README +51 -0
  12. data/server/node_modules/coffee-script/Rakefile +78 -0
  13. data/server/node_modules/coffee-script/bin/cake +7 -0
  14. data/server/node_modules/coffee-script/bin/coffee +7 -0
  15. data/server/node_modules/coffee-script/extras/jsl.conf +44 -0
  16. data/server/node_modules/coffee-script/lib/coffee-script/browser.js +92 -0
  17. data/server/node_modules/coffee-script/lib/coffee-script/cake.js +111 -0
  18. data/server/node_modules/coffee-script/lib/coffee-script/coffee-script.js +167 -0
  19. data/server/node_modules/coffee-script/lib/coffee-script/command.js +500 -0
  20. data/server/node_modules/coffee-script/lib/coffee-script/grammar.js +606 -0
  21. data/server/node_modules/coffee-script/lib/coffee-script/helpers.js +77 -0
  22. data/server/node_modules/coffee-script/lib/coffee-script/index.js +11 -0
  23. data/server/node_modules/coffee-script/lib/coffee-script/lexer.js +788 -0
  24. data/server/node_modules/coffee-script/lib/coffee-script/nodes.js +2986 -0
  25. data/server/node_modules/coffee-script/lib/coffee-script/optparse.js +138 -0
  26. data/server/node_modules/coffee-script/lib/coffee-script/parser.js +683 -0
  27. data/server/node_modules/coffee-script/lib/coffee-script/repl.js +261 -0
  28. data/server/node_modules/coffee-script/lib/coffee-script/rewriter.js +349 -0
  29. data/server/node_modules/coffee-script/lib/coffee-script/scope.js +146 -0
  30. data/server/node_modules/coffee-script/package.json +55 -0
  31. data/server/node_modules/connect-form/History.md +0 -6
  32. data/server/node_modules/connect-form/lib/connect-form.js +2 -4
  33. data/server/node_modules/connect-form/node_modules/formidable/Readme.md +64 -36
  34. data/server/node_modules/connect-form/node_modules/formidable/lib/incoming_form.js +5 -1
  35. data/server/node_modules/connect-form/node_modules/formidable/package.json +20 -6
  36. data/server/node_modules/connect-form/node_modules/formidable/test/common.js +5 -6
  37. data/server/node_modules/connect-form/node_modules/formidable/test/fixture/file/funkyfilename.txt +1 -0
  38. data/server/node_modules/connect-form/node_modules/formidable/test/fixture/js/special-chars-in-filename.js +1 -1
  39. data/server/node_modules/connect-form/node_modules/formidable/test/{slow → integration}/test-fixtures.js +38 -33
  40. data/server/node_modules/connect-form/node_modules/formidable/test/legacy/simple/test-incoming-form.js +11 -0
  41. data/server/node_modules/connect-form/node_modules/formidable/test/run.js +1 -6
  42. data/server/node_modules/connect-form/node_modules/formidable/test/unit/test-incoming-form.js +63 -0
  43. data/server/node_modules/connect-form/package.json +27 -5
  44. data/server/node_modules/cradle/README.md +10 -10
  45. data/server/node_modules/cradle/lib/cradle.js +117 -523
  46. data/server/node_modules/cradle/lib/cradle/database/attachments.js +120 -0
  47. data/server/node_modules/cradle/lib/cradle/database/changes.js +56 -0
  48. data/server/node_modules/cradle/lib/cradle/database/documents.js +215 -0
  49. data/server/node_modules/cradle/lib/cradle/database/index.js +65 -0
  50. data/server/node_modules/cradle/lib/cradle/database/views.js +125 -0
  51. data/server/node_modules/cradle/node_modules/follow/LICENSE +202 -0
  52. data/server/node_modules/cradle/node_modules/follow/README.md +164 -0
  53. data/server/node_modules/cradle/node_modules/follow/Rakefile +54 -0
  54. data/server/node_modules/cradle/node_modules/follow/api.js +35 -0
  55. data/server/node_modules/cradle/node_modules/follow/browser/eventemitter2.js +453 -0
  56. data/server/node_modules/cradle/node_modules/follow/browser/export.js +78 -0
  57. data/server/node_modules/cradle/node_modules/follow/browser/index.html +14 -0
  58. data/server/node_modules/cradle/node_modules/follow/browser/jquery-1.6.1.min.js +18 -0
  59. data/server/node_modules/cradle/node_modules/follow/browser/log4js.js +46 -0
  60. data/server/node_modules/cradle/node_modules/follow/browser/main.js +92 -0
  61. data/server/node_modules/cradle/node_modules/follow/browser/querystring.js +28 -0
  62. data/server/node_modules/cradle/node_modules/follow/browser/request.jquery.js +237 -0
  63. data/server/node_modules/cradle/node_modules/follow/browser/require.js +33 -0
  64. data/server/node_modules/cradle/node_modules/follow/browser/util.js +28 -0
  65. data/server/node_modules/cradle/node_modules/follow/cli.js +101 -0
  66. data/server/node_modules/cradle/node_modules/follow/lib/feed.js +556 -0
  67. data/server/node_modules/cradle/node_modules/follow/lib/index.js +66 -0
  68. data/server/node_modules/cradle/node_modules/follow/lib/stream.js +305 -0
  69. data/server/node_modules/cradle/node_modules/follow/node_modules/request/LICENSE +55 -0
  70. data/server/node_modules/cradle/node_modules/follow/node_modules/request/README.md +285 -0
  71. data/server/node_modules/cradle/node_modules/follow/node_modules/request/main.js +618 -0
  72. data/server/node_modules/cradle/node_modules/follow/node_modules/request/mimetypes.js +146 -0
  73. data/server/node_modules/cradle/node_modules/follow/node_modules/request/oauth.js +34 -0
  74. data/server/node_modules/cradle/node_modules/follow/node_modules/request/package.json +42 -0
  75. data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/googledoodle.png +0 -0
  76. data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/run.sh +6 -0
  77. data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/server.js +57 -0
  78. data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-body.js +90 -0
  79. data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-cookie.js +29 -0
  80. data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-cookiejar.js +90 -0
  81. data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-errors.js +30 -0
  82. data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-oauth.js +109 -0
  83. data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-pipes.js +167 -0
  84. data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-proxy.js +39 -0
  85. data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-timeout.js +87 -0
  86. data/server/node_modules/cradle/node_modules/follow/node_modules/request/uuid.js +19 -0
  87. data/server/node_modules/cradle/node_modules/follow/node_modules/request/vendor/cookie/index.js +55 -0
  88. data/server/node_modules/cradle/node_modules/follow/node_modules/request/vendor/cookie/jar.js +72 -0
  89. data/server/node_modules/cradle/node_modules/follow/package.json +45 -0
  90. data/server/node_modules/cradle/node_modules/follow/test/couch.js +153 -0
  91. data/server/node_modules/cradle/node_modules/follow/test/follow.js +136 -0
  92. data/server/node_modules/cradle/node_modules/follow/test/issues.js +178 -0
  93. data/server/node_modules/cradle/node_modules/follow/test/issues/10.js +24 -0
  94. data/server/node_modules/cradle/node_modules/follow/test/stream.js +493 -0
  95. data/server/node_modules/cradle/node_modules/request/LICENSE +55 -0
  96. data/server/node_modules/cradle/node_modules/request/README.md +287 -0
  97. data/server/node_modules/cradle/node_modules/request/forever.js +103 -0
  98. data/server/node_modules/cradle/node_modules/request/main.js +913 -0
  99. data/server/node_modules/cradle/node_modules/request/mimetypes.js +152 -0
  100. data/server/node_modules/cradle/node_modules/request/oauth.js +34 -0
  101. data/server/node_modules/cradle/node_modules/request/package.json +42 -0
  102. data/server/node_modules/cradle/node_modules/request/tests/googledoodle.png +0 -0
  103. data/server/node_modules/cradle/node_modules/request/tests/run.js +38 -0
  104. data/server/node_modules/cradle/node_modules/request/tests/server.js +82 -0
  105. data/server/node_modules/cradle/node_modules/request/tests/squid.conf +77 -0
  106. data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/ca.cnf +20 -0
  107. data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/ca.crl +0 -0
  108. data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/ca.crt +17 -0
  109. data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/ca.csr +13 -0
  110. data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/ca.key +18 -0
  111. data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/ca.srl +1 -0
  112. data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/server.cnf +19 -0
  113. data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/server.crt +16 -0
  114. data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/server.csr +11 -0
  115. data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/server.js +28 -0
  116. data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/server.key +9 -0
  117. data/server/node_modules/cradle/node_modules/request/tests/ssl/npm-ca.crt +16 -0
  118. data/server/node_modules/cradle/node_modules/request/tests/ssl/test.crt +15 -0
  119. data/server/node_modules/cradle/node_modules/request/tests/ssl/test.key +15 -0
  120. data/server/node_modules/cradle/node_modules/request/tests/test-body.js +95 -0
  121. data/server/node_modules/cradle/node_modules/request/tests/test-cookie.js +29 -0
  122. data/server/node_modules/cradle/node_modules/request/tests/test-cookiejar.js +90 -0
  123. data/server/node_modules/cradle/node_modules/request/tests/test-defaults.js +68 -0
  124. data/server/node_modules/cradle/node_modules/request/tests/test-errors.js +37 -0
  125. data/server/node_modules/cradle/node_modules/request/tests/test-headers.js +52 -0
  126. data/server/node_modules/cradle/node_modules/request/tests/test-httpModule.js +94 -0
  127. data/server/node_modules/cradle/node_modules/request/tests/test-https-strict.js +97 -0
  128. data/server/node_modules/cradle/node_modules/request/tests/test-https.js +86 -0
  129. data/server/node_modules/cradle/node_modules/request/tests/test-oauth.js +117 -0
  130. data/server/node_modules/cradle/node_modules/request/tests/test-params.js +92 -0
  131. data/server/node_modules/cradle/node_modules/request/tests/test-pipes.js +202 -0
  132. data/server/node_modules/cradle/node_modules/request/tests/test-proxy.js +39 -0
  133. data/server/node_modules/cradle/node_modules/request/tests/test-qs.js +28 -0
  134. data/server/node_modules/cradle/node_modules/request/tests/test-redirect.js +154 -0
  135. data/server/node_modules/cradle/node_modules/request/tests/test-timeout.js +87 -0
  136. data/server/node_modules/cradle/node_modules/request/tests/test-toJSON.js +14 -0
  137. data/server/node_modules/cradle/node_modules/request/tests/test-tunnel.js +61 -0
  138. data/server/node_modules/cradle/node_modules/request/tunnel.js +229 -0
  139. data/server/node_modules/cradle/node_modules/request/uuid.js +19 -0
  140. data/server/node_modules/cradle/node_modules/request/vendor/cookie/index.js +65 -0
  141. data/server/node_modules/cradle/node_modules/request/vendor/cookie/jar.js +72 -0
  142. data/server/node_modules/cradle/node_modules/vargs/package.json +33 -10
  143. data/server/node_modules/cradle/package.json +50 -12
  144. data/server/node_modules/cradle/test/cache-test.js +1 -4
  145. data/server/node_modules/cradle/test/connection-test.js +179 -0
  146. data/server/node_modules/cradle/test/database-attachment-test.js +344 -0
  147. data/server/node_modules/cradle/test/database-cache-test.js +132 -0
  148. data/server/node_modules/cradle/test/database-test.js +219 -0
  149. data/server/node_modules/cradle/test/database-view-test.js +141 -0
  150. data/server/node_modules/cradle/test/fixtures/databases.json +28 -1
  151. data/server/node_modules/cradle/test/helpers/seed.js +14 -5
  152. data/server/node_modules/cradle/test/response-test.js +1 -1
  153. data/server/node_modules/express/History.md +16 -0
  154. data/server/node_modules/express/bin/express +7 -6
  155. data/server/node_modules/express/lib-cov/application.js +510 -0
  156. data/server/node_modules/express/lib-cov/express.js +65 -0
  157. data/server/node_modules/express/lib-cov/middleware.js +54 -0
  158. data/server/node_modules/express/lib-cov/request.js +225 -0
  159. data/server/node_modules/express/lib-cov/response.js +611 -0
  160. data/server/node_modules/express/lib-cov/router/collection.js +40 -0
  161. data/server/node_modules/express/lib-cov/router/index.js +515 -0
  162. data/server/node_modules/express/lib-cov/router/methods.js +9 -0
  163. data/server/node_modules/express/lib-cov/router/route.js +68 -0
  164. data/server/node_modules/express/lib-cov/utils.js +151 -0
  165. data/server/node_modules/express/lib-cov/view.js +81 -0
  166. data/server/node_modules/express/lib/express.js +1 -1
  167. data/server/node_modules/express/lib/http.js +1 -2
  168. data/server/node_modules/express/lib/request.js +2 -2
  169. data/server/node_modules/express/lib/router/methods.js +10 -1
  170. data/server/node_modules/express/node_modules/connect/lib/connect.js +1 -1
  171. data/server/node_modules/express/node_modules/connect/lib/http.js +3 -2
  172. data/server/node_modules/express/node_modules/connect/lib/middleware/limit.js +0 -2
  173. data/server/node_modules/express/node_modules/connect/lib/middleware/session.js +1 -2
  174. data/server/node_modules/express/node_modules/connect/node_modules/formidable/Readme.md +42 -25
  175. data/server/node_modules/express/node_modules/connect/node_modules/formidable/lib/incoming_form.js +1 -0
  176. data/server/node_modules/express/node_modules/connect/node_modules/formidable/package.json +14 -3
  177. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/legacy/simple/test-incoming-form.js +11 -0
  178. data/server/node_modules/express/node_modules/connect/package.json +35 -7
  179. data/server/node_modules/express/node_modules/mime/package.json +30 -8
  180. data/server/node_modules/express/node_modules/mkdirp/README.markdown +35 -2
  181. data/server/node_modules/express/node_modules/mkdirp/examples/pow.js +1 -1
  182. data/server/node_modules/express/node_modules/mkdirp/index.js +72 -13
  183. data/server/node_modules/express/node_modules/mkdirp/package.json +39 -21
  184. data/server/node_modules/express/node_modules/mkdirp/test/chmod.js +38 -0
  185. data/server/node_modules/express/node_modules/mkdirp/test/clobber.js +37 -0
  186. data/server/node_modules/express/node_modules/mkdirp/test/perm.js +32 -0
  187. data/server/node_modules/express/node_modules/mkdirp/test/perm_sync.js +39 -0
  188. data/server/node_modules/express/node_modules/mkdirp/test/sync.js +27 -0
  189. data/server/node_modules/express/node_modules/mkdirp/test/umask.js +28 -0
  190. data/server/node_modules/express/node_modules/mkdirp/test/umask_sync.js +27 -0
  191. data/server/node_modules/express/node_modules/qs/History.md +10 -0
  192. data/server/node_modules/express/node_modules/qs/Readme.md +9 -2
  193. data/server/node_modules/express/node_modules/qs/examples.js +3 -0
  194. data/server/node_modules/express/node_modules/qs/lib/querystring.js +8 -6
  195. data/server/node_modules/express/node_modules/qs/package.json +26 -8
  196. data/server/node_modules/express/node_modules/qs/test/parse.js +13 -1
  197. data/server/node_modules/express/node_modules/qs/test/stringify.js +45 -37
  198. data/server/node_modules/express/package.json +55 -16
  199. data/server/node_modules/express/test.js +41 -0
  200. data/server/node_modules/knox/package.json +26 -4
  201. data/server/node_modules/node-uuid/package.json +40 -11
  202. data/server/node_modules/node-uuid/test/test.js +1 -1
  203. data/server/node_modules/nodemon/README.md +120 -0
  204. data/server/node_modules/nodemon/nodemon.js +518 -0
  205. data/server/node_modules/nodemon/nodemonignore.example +11 -0
  206. data/server/node_modules/nodemon/package.json +49 -0
  207. data/server/node_modules/restler/README.md +144 -94
  208. data/server/node_modules/restler/lib/multipartform.js +2 -0
  209. data/server/node_modules/restler/lib/restler.js +218 -61
  210. data/server/node_modules/restler/package.json +35 -8
  211. data/server/node_modules/restler/test/all.js +6 -1
  212. data/server/node_modules/restler/test/restler.js +624 -118
  213. data/server/package.json +14 -10
  214. data/server/web.coffee +64 -0
  215. data/server/web.js +15 -3
  216. metadata +170 -57
  217. data/server/index.js +0 -14
  218. data/server/node_modules/connect-form/LICENSE +0 -22
  219. data/server/node_modules/connect-form/index.js +0 -100
  220. data/server/node_modules/connect-form/node_modules/formidable/test/fast/test-incoming-form.js +0 -45
  221. data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/no-filename/generic.http +0 -13
  222. data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-chrome-13.http +0 -26
  223. data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-firefox-3.6.http +0 -24
  224. data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-safari-5.http +0 -23
  225. data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-chrome-12.http +0 -24
  226. data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-ie-7.http +0 -22
  227. data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-ie-8.http +0 -22
  228. data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-safari-5.http +0 -22
  229. data/server/node_modules/connect-form/node_modules/formidable/test/fixture/multi_video.upload +0 -0
  230. data/server/node_modules/cradle/Makefile +0 -10
  231. data/server/node_modules/cradle/test/cradle-test.js +0 -650
  232. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/no-filename/generic.http +0 -13
  233. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-chrome-13.http +0 -26
  234. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-firefox-3.6.http +0 -24
  235. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-safari-5.http +0 -23
  236. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-chrome-12.http +0 -24
  237. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-ie-7.http +0 -22
  238. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-ie-8.http +0 -22
  239. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-safari-5.http +0 -22
  240. data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/multi_video.upload +0 -0
  241. data/server/node_modules/express/node_modules/connect/test.js +0 -52
  242. data/server/node_modules/express/testing/foo/app.js +0 -35
  243. data/server/node_modules/express/testing/foo/package.json +0 -9
  244. data/server/node_modules/express/testing/foo/public/stylesheets/style.css +0 -8
  245. data/server/node_modules/express/testing/foo/routes/index.js +0 -10
  246. data/server/node_modules/express/testing/foo/views/index.jade +0 -2
  247. data/server/node_modules/express/testing/foo/views/layout.jade +0 -6
  248. data/server/node_modules/express/testing/index.js +0 -43
  249. data/server/node_modules/express/testing/public/test.txt +0 -2971
  250. data/server/node_modules/express/testing/views/page.html +0 -1
  251. data/server/node_modules/express/testing/views/page.jade +0 -3
  252. data/server/node_modules/express/testing/views/test.md +0 -1
  253. data/server/node_modules/express/testing/views/user/index.jade +0 -1
  254. data/server/node_modules/express/testing/views/user/list.jade +0 -1
  255. data/server/node_modules/knox/lib/knox/mime/index.js +0 -308
  256. data/server/node_modules/knox/lib/knox/mime/test.js +0 -59
  257. data/server/node_modules/node-uuid/test/benchmark-native +0 -0
  258. data/server/node_modules/on/index.js +0 -13
  259. data/server/node_modules/restler/test/test_helper.js +0 -163
  260. data/server/node_modules/spawner/index.js +0 -106
@@ -1,10 +1,37 @@
1
1
  {
2
- "name": "restler",
3
- "version": "0.2.4",
4
- "description": "An HTTP client library for node.js",
5
- "contributors": [{ "name": "Dan Webb", "email": "dan@danwebb.net" }],
6
- "homepage": "https://github.com/danwrong/restler",
7
- "directories" : { "lib" : "./lib" },
8
- "main" : "./lib/restler",
9
- "engines": { "node": ">= 0.3.7" }
2
+ "name": "restler",
3
+ "version": "2.0.1",
4
+ "description": "An HTTP client library for node.js",
5
+ "contributors": [
6
+ {
7
+ "name": "Dan Webb",
8
+ "email": "dan@danwebb.net"
9
+ }
10
+ ],
11
+ "homepage": "https://github.com/danwrong/restler",
12
+ "directories": {
13
+ "lib": "./lib"
14
+ },
15
+ "main": "./lib/restler",
16
+ "engines": {
17
+ "node": ">= 0.6.x"
18
+ },
19
+ "dependencies": {},
20
+ "devDependencies": {
21
+ "nodeunit": ">=0.5.0",
22
+ "xml2js": ">=0.1.0",
23
+ "yaml": ">=0.2.0",
24
+ "iconv": ">=1.0.0"
25
+ },
26
+ "_npmUser": {
27
+ "name": "ddollar",
28
+ "email": "ddollar@gmail.com"
29
+ },
30
+ "_id": "restler@2.0.1",
31
+ "optionalDependencies": {},
32
+ "_engineSupported": true,
33
+ "_npmVersion": "1.1.21",
34
+ "_nodeVersion": "v0.6.17",
35
+ "_defaultsLoaded": true,
36
+ "_from": "restler@2.x.x"
10
37
  }
@@ -1 +1,6 @@
1
- require('./restler');
1
+
2
+ require('./restler'); // debug
3
+ var nodeunit = require('nodeunit');
4
+ var reporter = nodeunit.reporters['default'];
5
+ process.chdir(__dirname);
6
+ reporter.run(['restler.js']);
@@ -1,168 +1,674 @@
1
- var helper = require('./test_helper'),
2
- rest = require('../lib/restler'),
3
- sys = require('util');
4
-
5
- helper.testCase("Basic Tests", helper.echoServer, {
6
- testRequestShouldTakePath: function(host, test) {
7
- rest.get(host + '/thing').on('complete', function(data) {
8
- test.ok(/^GET \/thing/.test(data), 'should hit /thing');
9
- });
10
- },
11
- testRequestShouldWorkWithNoPath: function(host, test) {
12
- rest.get(host).on('complete', function(data) {
13
- test.ok(/^GET \//.test(data), 'should hit /');
14
- });
15
- },
16
- testRequestShouldWorkPreserveQueryStringInURL: function(host, test) {
17
- rest.get(host + '/thing?boo=yah').on('complete', function(data) {
18
- test.ok(/^GET \/thing\?boo\=yah/.test(data), 'should hit /thing?boo=yah');
19
- });
20
- },
21
- testRequestShouldBeAbleToGET: function(host, test) {
22
- rest.get(host).on('complete', function(data) {
23
- test.ok(/^GET/.test(data), 'should be GET');
24
- });
25
- },
26
- testRequestShouldBeAbleToPUT: function(host, test) {
27
- rest.put(host).on('complete', function(data) {
28
- test.ok(/^PUT/.test(data), 'should be PUT');
29
- });
30
- },
31
- testRequestShouldBeAbleToPOST: function(host, test) {
32
- rest.post(host).on('complete', function(data) {
33
- test.ok(/^POST/.test(data), 'should be POST');
34
- });
35
- },
36
- testRequestShouldBeAbleToDELETE: function(host, test) {
37
- rest.del(host).on('complete', function(data) {
38
- test.ok(/^DELETE/.test(data), 'should be DELETE');
39
- });
40
- },
41
- testRequestShouldSerializeQuery: function(host, test) {
1
+
2
+ var rest = require('../lib/restler');
3
+ var http = require('http');
4
+ var sys = require('util');
5
+ var path = require('path');
6
+ var fs = require('fs');
7
+ var crypto = require('crypto');
8
+ var zlib = null;
9
+ var Iconv = null;
10
+
11
+ try {
12
+ zlib = require('zlib');
13
+ } catch (err) {}
14
+
15
+ try {
16
+ Iconv = require('iconv').Iconv;
17
+ } catch (err) {}
18
+
19
+ var p = sys.inspect;
20
+
21
+ var port = 9000;
22
+ var hostname = 'localhost';
23
+ var host = 'http://' + hostname + ':' + port;
24
+
25
+ var nodeunit = require('nodeunit');
26
+ nodeunit.assert.re = function(actual, expected, message) {
27
+ new RegExp(expected).test(actual) || nodeunit.assert.fail(actual, expected, message, '~=', nodeunit.assert.re);
28
+ };
29
+
30
+
31
+ function setup(response) {
32
+ return function(next) {
33
+ this.server = http.createServer(response);
34
+ this.server.listen(port, hostname, next);
35
+ };
36
+ }
37
+
38
+ function teardown() {
39
+ return function (next) {
40
+ this.server._handle && this.server.close();
41
+ process.nextTick(next);
42
+ };
43
+ }
44
+
45
+
46
+ function echoResponse(request, response) {
47
+ if (request.headers['x-connection-abort'] == 'true') {
48
+ request.connection.destroy();
49
+ return;
50
+ }
51
+ var echo = [];
52
+ echo.push(request.method + ' ' + request.url + ' HTTP/' + request.httpVersion);
53
+ for (var header in request.headers) {
54
+ echo.push(header + ': ' + request.headers[header]);
55
+ }
56
+ echo.push('', '');
57
+ echo = echo.join('\r\n');
58
+
59
+ request.addListener('data', function(chunk) {
60
+ echo += chunk.toString('binary');
61
+ });
62
+
63
+ request.addListener('end', function() {
64
+ response.writeHead(request.headers['x-status-code'] || 200, {
65
+ 'content-type': 'text/plain',
66
+ 'content-length': echo.length,
67
+ 'request-method': request.method.toLowerCase()
68
+ });
69
+ setTimeout(function() {
70
+ response.end(request.method == 'HEAD' ? undefined : echo);
71
+ }, request.headers['x-delay'] | 0);
72
+ });
73
+ }
74
+
75
+ module.exports['Basic'] = {
76
+
77
+ setUp: setup(echoResponse),
78
+ tearDown: teardown(),
79
+
80
+ 'Should GET': function (test) {
81
+ rest.get(host).on('complete', function(data) {
82
+ test.re(data, /^GET/, 'should be GET');
83
+ test.done();
84
+ });
85
+ },
86
+
87
+ 'Should PATCH': function(test) {
88
+ rest.patch(host).on('complete', function(data) {
89
+ test.re(data, /^PATCH/, 'should be PATCH');
90
+ test.done();
91
+ });
92
+ },
93
+
94
+ 'Should PUT': function(test) {
95
+ rest.put(host).on('complete', function(data) {
96
+ test.re(data, /^PUT/, 'should be PUT');
97
+ test.done();
98
+ });
99
+ },
100
+
101
+ 'Should POST': function(test) {
102
+ rest.post(host).on('complete', function(data) {
103
+ test.re(data, /^POST/, 'should be POST');
104
+ test.done();
105
+ });
106
+ },
107
+
108
+ 'Should DELETE': function(test) {
109
+ rest.del(host).on('complete', function(data) {
110
+ test.re(data, /^DELETE/, 'should be DELETE');
111
+ test.done();
112
+ });
113
+ },
114
+
115
+ 'Should HEAD': function(test) {
116
+ rest.head(host).on('complete', function(data, response) {
117
+ test.equal(response.headers['request-method'], 'head', 'should be HEAD');
118
+ test.done();
119
+ });
120
+ },
121
+
122
+ 'Should GET withouth path': function(test) {
123
+ rest.get(host).on('complete', function(data) {
124
+ test.re(data, /^GET \//, 'should hit /');
125
+ test.done();
126
+ });
127
+ },
128
+
129
+ 'Should GET path': function(test) {
130
+ rest.get(host + '/thing').on('complete', function(data) {
131
+ test.re(data, /^GET \/thing/, 'should hit /thing');
132
+ test.done();
133
+ });
134
+ },
135
+
136
+ 'Should preserve query string in url': function(test) {
137
+ rest.get(host + '/thing?boo=yah').on('complete', function(data) {
138
+ test.re(data, /^GET \/thing\?boo\=yah/, 'should hit /thing?boo=yah');
139
+ test.done();
140
+ });
141
+ },
142
+
143
+ 'Should serialize query': function(test) {
42
144
  rest.get(host, { query: { q: 'balls' } }).on('complete', function(data) {
43
- test.ok(/^GET \/\?q\=balls/.test(data), 'should hit /?q=balls');
145
+ test.re(data, /^GET \/\?q\=balls/, 'should hit /?q=balls');
146
+ test.done();
44
147
  });
45
148
  },
46
- testRequestShouldPostBody: function(host, test) {
47
- rest.post(host, { data: "balls" }).on('complete', function(data) {
48
- test.ok(/\r\n\r\nballs/.test(data), 'should have balls in the body')
149
+
150
+ 'Should POST body': function(test) {
151
+ rest.post(host, { data: 'balls' }).on('complete', function(data) {
152
+ test.re(data, /\r\n\r\nballs/, 'should have balls in the body');
153
+ test.done();
49
154
  });
50
155
  },
51
- testRequestShouldSerializePostBody: function(host, test) {
156
+
157
+ 'Should serialize POST body': function(test) {
52
158
  rest.post(host, { data: { q: 'balls' } }).on('complete', function(data) {
53
- test.ok(/content-type\: application\/x-www-form-urlencoded/.test(data),
54
- 'should set content-type');
55
- test.ok(/content-length\: 7/.test(data), 'should set content-length');
56
- test.ok(/\r\n\r\nq=balls/.test(data), 'should have balls in the body')
159
+ test.re(data, /content-type\: application\/x-www-form-urlencoded/, 'should set content-type');
160
+ test.re(data, /content-length\: 7/, 'should set content-length');
161
+ test.re(data, /\r\n\r\nq=balls/, 'should have balls in the body');
162
+ test.done();
57
163
  });
58
164
  },
59
- testRequestShouldSendHeaders: function(host, test) {
165
+
166
+ 'Should send headers': function(test) {
60
167
  rest.get(host, {
61
168
  headers: { 'Content-Type': 'application/json' }
62
169
  }).on('complete', function(data) {
63
- test.ok(/content\-type\: application\/json/.test(data), 'should content type header')
170
+ test.re(data, /content\-type\: application\/json/, 'should have "content-type" header');
171
+ test.done();
64
172
  });
65
173
  },
66
- testRequestShouldSendBasicAuth: function(host, test) {
174
+
175
+ 'Should send basic auth': function(test) {
67
176
  rest.post(host, { username: 'danwrong', password: 'flange' }).on('complete', function(data) {
68
- test.ok(/authorization\: Basic ZGFud3Jvbmc6Zmxhbmdl/.test(data), 'should have auth header')
177
+ test.re(data, /authorization\: Basic ZGFud3Jvbmc6Zmxhbmdl/, 'should have "authorization "header');
178
+ test.done();
69
179
  });
70
180
  },
71
- testRequestShouldSendBasicAuthIfInURL: function(host, test) {
72
- var port = host.match(/\:(\d+)/)[1];
73
- host = "http://danwrong:flange@localhost:" + port;
74
- rest.post(host).on('complete', function(data) {
75
- test.ok(/authorization\: Basic ZGFud3Jvbmc6Zmxhbmdl/.test(data), 'should have auth header')
181
+
182
+ 'Should send basic auth if in url': function(test) {
183
+ rest.post('http://danwrong:flange@' + hostname + ':' + port).on('complete', function(data) {
184
+ test.re(data, /authorization\: Basic ZGFud3Jvbmc6Zmxhbmdl/, 'should have "authorization" header');
185
+ test.done();
76
186
  });
77
187
  },
78
- testRequestShouldFire2XXAnd200Events: function(host, test) {
79
- var count = 0;
80
-
188
+
189
+ 'Should fire 2XX and 200 events': function(test) {
190
+ test.expect(3);
81
191
  rest.get(host).on('2XX', function() {
82
- count++;
192
+ test.ok(true);
83
193
  }).on('200', function() {
84
- count++;
194
+ test.ok(true);
85
195
  }).on('complete', function() {
86
- test.equal(2, count);
196
+ test.ok(true);
197
+ test.done();
87
198
  });
88
199
  },
89
- testRequestShouldFireError4XXand404EventsFor404: function(host, test) {
90
- var count = 0;
91
-
92
- rest.get(host, { headers: { 'X-Give-Me-Status': 404 }}).on('error', function() {
93
- count++;
200
+
201
+ 'Should fire fail, 4XX and 404 events for 404': function(test) {
202
+ test.expect(4);
203
+ rest.get(host, { headers: { 'x-status-code': 404 }}).on('fail', function() {
204
+ test.ok(true);
94
205
  }).on('4XX', function() {
95
- count++;
206
+ test.ok(true);
96
207
  }).on('404', function() {
97
- count++;
208
+ test.ok(true);
98
209
  }).on('complete', function() {
99
- test.equal(3, count);
210
+ test.ok(true);
211
+ test.done();
100
212
  });
213
+ },
214
+
215
+ 'Should fire error and complete events on connection abort': function(test) {
216
+ test.expect(2);
217
+ rest.get(host, { headers: { 'x-connection-abort': 'true' }}).on('error', function() {
218
+ test.ok(true);
219
+ }).on('complete', function() {
220
+ test.ok(true);
221
+ test.done();
222
+ });
223
+ },
224
+
225
+ 'Should correctly retry': function(test) {
226
+ var counter = 0;
227
+ rest.get(host, { headers: { 'x-connection-abort': 'true' }}).on('complete', function() {
228
+ if (++counter < 3) {
229
+ this.retry(10);
230
+ } else {
231
+ test.ok(true);
232
+ test.done();
233
+ }
234
+ });
235
+ },
236
+
237
+ 'Should correctly retry after abort': function(test) {
238
+ var counter = 0;
239
+ rest.get(host).on('complete', function() {
240
+ if (++counter < 3) {
241
+ this.retry().abort();
242
+ } else {
243
+ test.ok(true);
244
+ test.done();
245
+ }
246
+ }).abort();
247
+ },
248
+
249
+ 'Should correctly retry while pending': function(test) {
250
+ var counter = 0, request;
251
+ function command() {
252
+ var args = [].slice.call(arguments);
253
+ var method = args.shift();
254
+ method && setTimeout(function() {
255
+ request[method]();
256
+ command.apply(null, args);
257
+ }, 50);
258
+ }
259
+
260
+ request = rest.get(host, { headers: { 'x-delay': '1000' } }).on('complete', function() {
261
+ if (++counter < 3) {
262
+ command('retry', 'abort');
263
+ } else {
264
+ test.ok(true);
265
+ test.done();
266
+ }
267
+ });
268
+ command('abort');
101
269
  }
102
- });
103
-
104
- helper.testCase('Multipart Tests', helper.echoServer, {
105
- testMultipartRequestWithSimpleVars: function(host, test) {
106
- rest.post(host, {
107
- data: { a: 1, b: 'thing' },
108
- multipart: true
109
- }).on('complete', function(data) {
110
- test.ok(/content-type\: multipart\/form-data/.test(data), 'should set content type')
111
- test.ok(/name="a"(\s)+1/.test(data), 'should send a=1');
112
- test.ok(/name="b"(\s)+thing/.test(data), 'should send b=thing');
113
- });
114
- }
115
- });
116
-
117
-
118
- helper.testCase("Deserialization Tests", helper.dataServer, {
119
- testAutoSerializerShouldParseJSON: function(host, test) {
120
- rest.get(host, {
121
- headers: { 'Accepts': 'application/json' }
270
+
271
+ };
272
+
273
+ module.exports['Multipart'] = {
274
+
275
+ setUp: setup(echoResponse),
276
+ tearDown: teardown(),
277
+
278
+ 'Test multipart request with simple vars': function(test) {
279
+ rest.post(host, {
280
+ data: { a: 10, b: 'thing' },
281
+ multipart: true
122
282
  }).on('complete', function(data) {
123
- test.equal(true, data.ok, "returned " + sys.inspect(data));
283
+ test.re(data, /content-type\: multipart\/form-data/, 'should set "content-type" header')
284
+ test.re(data, /name="a"(\s)+10/, 'should send a=10');
285
+ test.re(data, /name="b"(\s)+thing/, 'should send b=thing');
286
+ test.re(data, /content-length: 200/, 'should send content-length header');
287
+
288
+ test.done();
289
+ });
290
+ }
291
+
292
+ };
293
+
294
+
295
+ function dataResponse(request, response) {
296
+ switch (request.url) {
297
+ case '/json':
298
+ response.writeHead(200, { 'content-type': 'application/json' });
299
+ response.end('{ "ok": true }');
300
+ break;
301
+ case '/xml':
302
+ response.writeHead(200, { 'content-type': 'application/xml' });
303
+ response.end('<document><ok>true</ok></document>');
304
+ break;
305
+ case '/yaml':
306
+ response.writeHead(200, { 'content-type': 'application/yaml' });
307
+ response.end('ok: true');
308
+ break;
309
+ case '/gzip':
310
+ response.writeHead(200, { 'content-encoding': 'gzip' });
311
+ response.end(Buffer('H4sIAAAAAAAAA0vOzy0oSi0uTk1RSEksSUweHFwADdgOgJYAAAA=', 'base64'));
312
+ break;
313
+ case '/deflate':
314
+ response.writeHead(200, { 'content-encoding': 'deflate' });
315
+ response.end(Buffer('eJxLzs8tKEotLk5NUUhJLElMHhxcAI9GO1c=', 'base64'));
316
+ break;
317
+ case '/truth':
318
+ response.writeHead(200, {
319
+ 'content-encoding': 'deflate',
320
+ 'content-type': 'application/json'
321
+ });
322
+ response.end(Buffer('eJw1i0sKgDAQQ++S9Sj+cDFXEReCoy2UCv0oIt7dEZEsEvKSC4eZErjoCTaCr5uQjICHilQjYfLxkAD+g/IN3BCcXXT3GSF7u0uI2vjs3HubwW1ZdwRRcCZj/QpOIcv9ACXbJLo=', 'base64'));
323
+ break;
324
+ case '/binary':
325
+ response.writeHead(200);
326
+ response.end(Buffer([9, 30, 64, 135, 200]));
327
+ break;
328
+ case '/push-json':
329
+ var echo = '';
330
+ request.addListener('data', function(chunk) {
331
+ echo += chunk.toString('binary');
332
+ });
333
+ request.addListener('end', function() {
334
+ response.writeHead(200, {
335
+ 'content-type': 'application/json'
336
+ });
337
+ response.end(JSON.stringify(JSON.parse(echo)));
338
+ });
339
+ break;
340
+ case '/custom-mime':
341
+ response.writeHead(200, {
342
+ 'content-type': 'application/vnd.github.beta.raw+json; charset=UTF-8'
343
+ });
344
+ response.end(JSON.stringify([6,6,6]));
345
+ break;
346
+ case '/mal-json':
347
+ response.writeHead(200, { 'content-type': 'application/json' });
348
+ response.end('Чебурашка');
349
+ break;
350
+ case '/mal-xml':
351
+ response.writeHead(200, { 'content-type': 'application/xml' });
352
+ response.end('Чебурашка');
353
+ break;
354
+ case '/mal-yaml':
355
+ response.writeHead(200, { 'content-type': 'application/yaml' });
356
+ response.end('{Чебурашка');
357
+ break;
358
+ case '/abort':
359
+ setTimeout(function() {
360
+ response.writeHead(200);
361
+ response.end('not aborted');
362
+ }, 100);
363
+ break;
364
+ case '/charset':
365
+ response.writeHead(200, {
366
+ 'content-type': 'text/plain; charset=windows-1251'
367
+ });
368
+ response.end(Buffer('e0e1e2e3e4e5b8e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff', 'hex'));
369
+ break;
370
+ default:
371
+ response.writeHead(404);
372
+ response.end();
373
+ }
374
+ }
375
+
376
+ module.exports['Deserialization'] = {
377
+
378
+ setUp: setup(dataResponse),
379
+ tearDown: teardown(),
380
+
381
+ 'Should parse JSON': function(test) {
382
+ rest.get(host + '/json').on('complete', function(data) {
383
+ test.equal(data.ok, true, 'returned: ' + p(data));
384
+ test.done();
124
385
  });
125
386
  },
126
- testAutoSerializerShouldParseXML: function(host, test) {
127
- rest.get(host, {
128
- headers: { 'Accepts': 'application/xml' }
129
- }).on('complete', function(data) {
130
- test.equal("true", data.ok, "returned " + sys.inspect(data));
387
+
388
+ 'Should parse XML': function(test) {
389
+ rest.get(host + '/xml').on('complete', function(data, response) {
390
+ test.equal(data.ok, 'true', 'returned: ' + response.raw + ' || ' + p(data));
391
+ test.done();
131
392
  });
132
393
  },
133
- testAutoSerializerShouldParseYAML: function(host, test) {
134
- rest.get(host, {
135
- headers: { 'Accepts': 'application/yaml' }
394
+
395
+ 'Should parse YAML': function(test) {
396
+ rest.get(host + '/yaml').on('complete', function(data) {
397
+ test.equal(data.ok, true, 'returned: ' + p(data));
398
+ test.done();
399
+ });
400
+ },
401
+
402
+ 'Should gunzip': function(test) {
403
+ if (zlib) {
404
+ rest.get(host + '/gzip').on('complete', function(data) {
405
+ test.re(data, /^(compressed data){10}$/, 'returned: ' + p(data));
406
+ test.done();
407
+ });
408
+ } else {
409
+ test.done();
410
+ }
411
+ },
412
+
413
+ 'Should inflate': function(test) {
414
+ if (zlib) {
415
+ rest.get(host + '/deflate').on('complete', function(data) {
416
+ test.re(data, /^(compressed data){10}$/, 'returned: ' + p(data));
417
+ test.done();
418
+ })
419
+ } else {
420
+ test.done();
421
+ }
422
+ },
423
+
424
+ 'Should decode and parse': function(test) {
425
+ if (zlib) {
426
+ rest.get(host + '/truth').on('complete', function(data) {
427
+ try {
428
+ with (data) {
429
+ var result = what + (is + the + answer + to + life + the + universe + and + everything).length;
430
+ }
431
+ test.equal(result, 42, 'returned: ' + p(data));
432
+ } catch (err) {
433
+ test.ok(false, 'returned: ' + p(data));
434
+ }
435
+ test.done();
436
+ })
437
+ } else {
438
+ test.done();
439
+ }
440
+ },
441
+
442
+ 'Should decode as buffer': function(test) {
443
+ rest.get(host + '/binary', { decoding: 'buffer' }).on('complete', function(data) {
444
+ test.ok(data instanceof Buffer, 'should be buffer');
445
+ test.equal(data.toString('base64'), 'CR5Ah8g=', 'returned: ' + p(data));
446
+ test.done();
447
+ })
448
+ },
449
+
450
+ 'Should decode as binary': function(test) {
451
+ rest.get(host + '/binary', { decoding: 'binary' }).on('complete', function(data) {
452
+ test.ok(typeof data == 'string', 'should be string: ' + p(data));
453
+ test.equal(data, '\t\u001e@‡È', 'returned: ' + p(data));
454
+ test.done();
455
+ })
456
+ },
457
+
458
+ 'Should decode as base64': function(test) {
459
+ rest.get(host + '/binary', { decoding: 'base64' }).on('complete', function(data) {
460
+ test.ok(typeof data == 'string', 'should be string: ' + p(data));
461
+ test.equal(data, 'CR5Ah8g=', 'returned: ' + p(data));
462
+ test.done();
463
+ })
464
+ },
465
+
466
+ 'Should post and parse JSON': function(test) {
467
+ var obj = { secret : 'very secret string' };
468
+ rest.post(host + '/push-json', {
469
+ headers: {
470
+ 'content-type': 'application/json'
471
+ },
472
+ data: JSON.stringify(obj)
136
473
  }).on('complete', function(data) {
137
- test.equal(true, data.ok, "returned " + sys.inspect(data));
474
+ test.equal(obj.secret, data.secret, 'returned: ' + p(data));
475
+ test.done();
476
+ })
477
+ },
478
+
479
+ 'Should post and parse JSON via shortcut method': function(test) {
480
+ var obj = { secret : 'very secret string' };
481
+ rest.postJson(host + '/push-json', obj).on('complete', function(data) {
482
+ test.equal(obj.secret, data.secret, 'returned: ' + p(data));
483
+ test.done();
138
484
  });
485
+ },
486
+
487
+ 'Should understand custom mime-type': function(test) {
488
+ rest.parsers.auto.matchers['application/vnd.github+json'] = function(data, callback) {
489
+ rest.parsers.json.call(this, data, function(err, data) {
490
+ err || (data.__parsedBy__ = 'github');
491
+ callback(err, data);
492
+ });
493
+ };
494
+ rest.get(host + '/custom-mime').on('complete', function(data) {
495
+ test.expect(3);
496
+ test.ok(Array.isArray(data), 'should be array, returned: ' + p(data));
497
+ test.equal(data.join(''), '666', 'should be [6,6,6], returned: ' + p(data));
498
+ test.equal(data.__parsedBy__, 'github', 'should use vendor-specific parser, returned: ' + p(data.__parsedBy__));
499
+ test.done();
500
+ });
501
+ },
502
+
503
+ 'Should correctly soft-abort request': function(test) {
504
+ test.expect(4);
505
+ rest.get(host + '/abort').on('complete', function(data) {
506
+ test.equal(data, null, 'data should be null');
507
+ test.equal(this.aborted, true, 'should be aborted');
508
+ test.done();
509
+ }).on('error', function(err) {
510
+ test.ok(false, 'should not emit error event');
511
+ }).on('abort', function(err) {
512
+ test.equal(err, null, 'err should be null');
513
+ test.equal(this.aborted, true, 'should be aborted');
514
+ }).on('success', function() {
515
+ test.ok(false, 'should not emit success event');
516
+ }).on('fail', function() {
517
+ test.ok(false, 'should not emit fail event');
518
+ }).abort();
519
+ },
520
+
521
+ 'Should correctly hard-abort request': function(test) {
522
+ test.expect(4);
523
+ rest.get(host + '/abort').on('complete', function(data) {
524
+ test.ok(data instanceof Error, 'should be error, got: ' + p(data));
525
+ test.equal(this.aborted, true, 'should be aborted');
526
+ test.done();
527
+ }).on('error', function(err) {
528
+ test.ok(err instanceof Error, 'should be error, got: ' + p(err));
529
+ }).on('abort', function(err) {
530
+ test.equal(this.aborted, true, 'should be aborted');
531
+ }).on('success', function() {
532
+ test.ok(false, 'should not emit success event');
533
+ }).on('fail', function() {
534
+ test.ok(false, 'should not emit fail event');
535
+ }).abort(true);
536
+ },
537
+
538
+ 'Should correctly handle malformed JSON': function(test) {
539
+ test.expect(4);
540
+ rest.get(host + '/mal-json').on('complete', function(data, response) {
541
+ test.ok(data instanceof Error, 'should be instanceof Error, got: ' + p(data));
542
+ test.re(data.message, /^Failed to parse/, 'should contain "Failed to parse", got: ' + p(data.message));
543
+ test.equal(response.raw, 'Чебурашка', 'should be "Чебурашка", got: ' + p(response.raw));
544
+ test.done();
545
+ }).on('error', function(err) {
546
+ test.ok(err instanceof Error, 'should be instanceof Error, got: ' + p(err));
547
+ }).on('success', function() {
548
+ test.ok(false, 'should not have got here');
549
+ }).on('fail', function() {
550
+ test.ok(false, 'should not have got here');
551
+ });
552
+ },
553
+
554
+ 'Should correctly handle malformed XML': function(test) {
555
+ test.expect(4);
556
+ rest.get(host + '/mal-xml').on('complete', function(data, response) {
557
+ test.ok(data instanceof Error, 'should be instanceof Error, got: ' + p(data));
558
+ test.re(data.message, /^Failed to parse/, 'should contain "Failed to parse", got: ' + p(data.message));
559
+ test.equal(response.raw, 'Чебурашка', 'should be "Чебурашка", got: ' + p(response.raw));
560
+ test.done();
561
+ }).on('error', function(err) {
562
+ test.ok(err instanceof Error, 'should be instanceof Error, got: ' + p(err));
563
+ }).on('success', function() {
564
+ test.ok(false, 'should not have got here');
565
+ }).on('fail', function() {
566
+ test.ok(false, 'should not have got here');
567
+ });
568
+ },
569
+
570
+ 'Should correctly handle malformed YAML': function(test) {
571
+ test.expect(4);
572
+ rest.get(host + '/mal-yaml').on('complete', function(data, response) {
573
+ test.ok(data instanceof Error, 'should be instanceof Error, got: ' + p(data));
574
+ test.re(data.message, /^Failed to parse/, 'should contain "Failed to parse", got: ' + p(data.message));
575
+ test.equal(response.raw, '{Чебурашка', 'should be "{Чебурашка", got: ' + p(response.raw));
576
+ test.done();
577
+ }).on('error', function(err) {
578
+ test.ok(err instanceof Error, 'should be instanceof Error, got: ' + p(err));
579
+ }).on('success', function() {
580
+ test.ok(false, 'should not have got here');
581
+ }).on('fail', function() {
582
+ test.ok(false, 'should not have got here');
583
+ });
584
+ }
585
+
586
+ };
587
+
588
+ if (Iconv) {
589
+ module.exports['Deserialization']['Should correctly convert charsets '] = function(test) {
590
+ rest.get(host + '/charset').on('complete', function(data) {
591
+ test.equal(data, 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя');
592
+ test.done();
593
+ });
594
+ };
595
+ }
596
+
597
+
598
+ function redirectResponse(request, response) {
599
+ if (request.url == '/redirected') {
600
+ response.writeHead(200, { 'content-type': 'text/plain' });
601
+ response.end('redirected');
602
+ } else if (request.url == '/') {
603
+ response.writeHead(301, {
604
+ 'location': host + '/' + (request.headers['x-redirects'] ? '1' : 'redirected')
605
+ });
606
+ response.end('redirect');
607
+ } else {
608
+ var count = parseInt(request.url.substr(1));
609
+ var max = parseInt(request.headers['x-redirects']);
610
+ response.writeHead(count < max ? 301 : 200, {
611
+ 'location': host + '/' + (count + 1)
612
+ });
613
+ response.end(count.toString(10));
139
614
  }
140
- });
615
+ }
616
+
617
+ module.exports['Redirect'] = {
141
618
 
142
- helper.testCase('Redirect Tests', helper.redirectServer, {
143
- testShouldAutomaticallyFollowRedirects: function(host, test) {
619
+ setUp: setup(redirectResponse),
620
+ tearDown: teardown(),
621
+
622
+ 'Should follow redirects': function(test) {
144
623
  rest.get(host).on('complete', function(data) {
145
- test.equal('Hell Yeah!', data, "returned " + sys.inspect(data));
624
+ test.equal(data, 'redirected', 'returned: ' + p(data));
625
+ test.done();
626
+ });
627
+ },
628
+
629
+ 'Should follow multiple redirects': function(test) {
630
+ rest.get(host, {
631
+ headers: { 'x-redirects': '5' }
632
+ }).on('complete', function(data) {
633
+ test.equal(data, '5', 'returned: ' + p(data));
634
+ test.done();
146
635
  });
147
636
  }
148
- });
149
637
 
150
- helper.testCase('Content-Length Tests', helper.contentLengthServer, {
151
- testRequestHeaderIncludesContentLengthWithJSONData: function(host, test){
152
- var jsonString = JSON.stringify({ greeting: 'hello world' });
638
+ };
639
+
640
+
641
+ function contentLengthResponse(request, response) {
642
+ response.writeHead(200, { 'content-type': 'text/plain' });
643
+ if ('content-length' in request.headers) {
644
+ response.write(request.headers['content-length']);
645
+ } else {
646
+ response.write('content-length is not set');
647
+ }
648
+ response.end();
649
+ }
650
+
651
+ module.exports['Content-Length'] = {
652
+
653
+ setUp: setup(contentLengthResponse),
654
+ tearDown: teardown(),
655
+
656
+ 'JSON content length': function(test) {
153
657
  rest.post(host, {
154
- data: jsonString
155
- }).on('complete', function(data){
658
+ data: JSON.stringify({ greeting: 'hello world' })
659
+ }).on('complete', function(data) {
156
660
  test.equal(26, data, 'should set content-length');
661
+ test.done();
157
662
  });
158
663
  },
159
- testJSONMultibyteContentLength: function (host, test){
160
- var multibyteData = JSON.stringify({ greeting: 'こんにちは世界' });
664
+
665
+ 'JSON multibyte content length': function (test) {
161
666
  rest.post(host, {
162
- data: multibyteData
667
+ data: JSON.stringify({ greeting: 'こんにちは世界' })
163
668
  }).on('complete', function(data) {
164
- test.notEqual(22, data, 'should unicode string length');
165
669
  test.equal(36, data, 'should byte-size content-length');
670
+ test.done();
166
671
  });
167
672
  }
168
- });
673
+
674
+ };