benschwarz-smoke 0.5.7 → 0.5.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. data/Rakefile +6 -0
  2. data/VERSION.yml +1 -1
  3. metadata +65 -196
  4. data/Gemfile +0 -10
  5. data/bin/edit_json.rb +0 -3
  6. data/bin/restclient +0 -3
  7. data/vendor/gems/cache/crack-0.1.1.gem +0 -0
  8. data/vendor/gems/cache/fakeweb-1.2.5.gem +0 -0
  9. data/vendor/gems/cache/json-1.1.3.gem +0 -0
  10. data/vendor/gems/cache/rest-client-1.0.1.gem +0 -0
  11. data/vendor/gems/cache/simple-rss-1.2.gem +0 -0
  12. data/vendor/gems/cache/wycats-moneta-0.6.0.gem +0 -0
  13. data/vendor/gems/environment.rb +0 -83
  14. data/vendor/gems/gems/crack-0.1.1/LICENSE +0 -20
  15. data/vendor/gems/gems/crack-0.1.1/README.rdoc +0 -22
  16. data/vendor/gems/gems/crack-0.1.1/VERSION.yml +0 -4
  17. data/vendor/gems/gems/crack-0.1.1/lib/crack.rb +0 -7
  18. data/vendor/gems/gems/crack-0.1.1/lib/crack/core_extensions.rb +0 -126
  19. data/vendor/gems/gems/crack-0.1.1/lib/crack/json.rb +0 -66
  20. data/vendor/gems/gems/crack-0.1.1/lib/crack/xml.rb +0 -211
  21. data/vendor/gems/gems/crack-0.1.1/test/crack_test.rb +0 -4
  22. data/vendor/gems/gems/crack-0.1.1/test/json_test.rb +0 -42
  23. data/vendor/gems/gems/crack-0.1.1/test/test_helper.rb +0 -12
  24. data/vendor/gems/gems/crack-0.1.1/test/xml_test.rb +0 -451
  25. data/vendor/gems/gems/fakeweb-1.2.5/CHANGELOG +0 -163
  26. data/vendor/gems/gems/fakeweb-1.2.5/LICENSE.txt +0 -281
  27. data/vendor/gems/gems/fakeweb-1.2.5/README.rdoc +0 -193
  28. data/vendor/gems/gems/fakeweb-1.2.5/Rakefile +0 -76
  29. data/vendor/gems/gems/fakeweb-1.2.5/lib/fake_web.rb +0 -172
  30. data/vendor/gems/gems/fakeweb-1.2.5/lib/fake_web/ext/net_http.rb +0 -71
  31. data/vendor/gems/gems/fakeweb-1.2.5/lib/fake_web/registry.rb +0 -103
  32. data/vendor/gems/gems/fakeweb-1.2.5/lib/fake_web/responder.rb +0 -113
  33. data/vendor/gems/gems/fakeweb-1.2.5/lib/fake_web/response.rb +0 -10
  34. data/vendor/gems/gems/fakeweb-1.2.5/lib/fake_web/stub_socket.rb +0 -15
  35. data/vendor/gems/gems/fakeweb-1.2.5/lib/fake_web/utility.rb +0 -22
  36. data/vendor/gems/gems/fakeweb-1.2.5/lib/fakeweb.rb +0 -2
  37. data/vendor/gems/gems/fakeweb-1.2.5/test/fixtures/google_response_from_curl +0 -12
  38. data/vendor/gems/gems/fakeweb-1.2.5/test/fixtures/google_response_with_transfer_encoding +0 -17
  39. data/vendor/gems/gems/fakeweb-1.2.5/test/fixtures/google_response_without_transfer_encoding +0 -11
  40. data/vendor/gems/gems/fakeweb-1.2.5/test/fixtures/test_example.txt +0 -1
  41. data/vendor/gems/gems/fakeweb-1.2.5/test/fixtures/test_txt_file +0 -3
  42. data/vendor/gems/gems/fakeweb-1.2.5/test/test_allow_net_connect.rb +0 -85
  43. data/vendor/gems/gems/fakeweb-1.2.5/test/test_deprecations.rb +0 -54
  44. data/vendor/gems/gems/fakeweb-1.2.5/test/test_fake_authentication.rb +0 -92
  45. data/vendor/gems/gems/fakeweb-1.2.5/test/test_fake_web.rb +0 -518
  46. data/vendor/gems/gems/fakeweb-1.2.5/test/test_fake_web_open_uri.rb +0 -58
  47. data/vendor/gems/gems/fakeweb-1.2.5/test/test_helper.rb +0 -74
  48. data/vendor/gems/gems/fakeweb-1.2.5/test/test_missing_open_uri.rb +0 -25
  49. data/vendor/gems/gems/fakeweb-1.2.5/test/test_precedence.rb +0 -51
  50. data/vendor/gems/gems/fakeweb-1.2.5/test/test_query_string.rb +0 -45
  51. data/vendor/gems/gems/fakeweb-1.2.5/test/test_regexes.rb +0 -103
  52. data/vendor/gems/gems/fakeweb-1.2.5/test/test_response_headers.rb +0 -67
  53. data/vendor/gems/gems/fakeweb-1.2.5/test/test_trailing_slashes.rb +0 -53
  54. data/vendor/gems/gems/fakeweb-1.2.5/test/test_utility.rb +0 -70
  55. data/vendor/gems/gems/json-1.1.3/CHANGES +0 -93
  56. data/vendor/gems/gems/json-1.1.3/GPL +0 -340
  57. data/vendor/gems/gems/json-1.1.3/README +0 -78
  58. data/vendor/gems/gems/json-1.1.3/RUBY +0 -58
  59. data/vendor/gems/gems/json-1.1.3/Rakefile +0 -309
  60. data/vendor/gems/gems/json-1.1.3/TODO +0 -1
  61. data/vendor/gems/gems/json-1.1.3/VERSION +0 -1
  62. data/vendor/gems/gems/json-1.1.3/benchmarks/benchmark.txt +0 -133
  63. data/vendor/gems/gems/json-1.1.3/benchmarks/benchmark_generator.rb +0 -48
  64. data/vendor/gems/gems/json-1.1.3/benchmarks/benchmark_parser.rb +0 -26
  65. data/vendor/gems/gems/json-1.1.3/benchmarks/benchmark_rails.rb +0 -26
  66. data/vendor/gems/gems/json-1.1.3/bin/edit_json.rb +0 -10
  67. data/vendor/gems/gems/json-1.1.3/bin/prettify_json.rb +0 -76
  68. data/vendor/gems/gems/json-1.1.3/data/example.json +0 -1
  69. data/vendor/gems/gems/json-1.1.3/data/index.html +0 -38
  70. data/vendor/gems/gems/json-1.1.3/data/prototype.js +0 -4184
  71. data/vendor/gems/gems/json-1.1.3/ext/json/ext/generator.bundle +0 -0
  72. data/vendor/gems/gems/json-1.1.3/ext/json/ext/generator/Makefile +0 -150
  73. data/vendor/gems/gems/json-1.1.3/ext/json/ext/generator/extconf.rb +0 -9
  74. data/vendor/gems/gems/json-1.1.3/ext/json/ext/generator/generator.bundle +0 -0
  75. data/vendor/gems/gems/json-1.1.3/ext/json/ext/generator/generator.c +0 -875
  76. data/vendor/gems/gems/json-1.1.3/ext/json/ext/generator/generator.o +0 -0
  77. data/vendor/gems/gems/json-1.1.3/ext/json/ext/generator/unicode.c +0 -182
  78. data/vendor/gems/gems/json-1.1.3/ext/json/ext/generator/unicode.h +0 -53
  79. data/vendor/gems/gems/json-1.1.3/ext/json/ext/generator/unicode.o +0 -0
  80. data/vendor/gems/gems/json-1.1.3/ext/json/ext/parser.bundle +0 -0
  81. data/vendor/gems/gems/json-1.1.3/ext/json/ext/parser/Makefile +0 -150
  82. data/vendor/gems/gems/json-1.1.3/ext/json/ext/parser/extconf.rb +0 -9
  83. data/vendor/gems/gems/json-1.1.3/ext/json/ext/parser/parser.bundle +0 -0
  84. data/vendor/gems/gems/json-1.1.3/ext/json/ext/parser/parser.c +0 -1758
  85. data/vendor/gems/gems/json-1.1.3/ext/json/ext/parser/parser.o +0 -0
  86. data/vendor/gems/gems/json-1.1.3/ext/json/ext/parser/parser.rl +0 -638
  87. data/vendor/gems/gems/json-1.1.3/ext/json/ext/parser/unicode.c +0 -154
  88. data/vendor/gems/gems/json-1.1.3/ext/json/ext/parser/unicode.h +0 -58
  89. data/vendor/gems/gems/json-1.1.3/ext/json/ext/parser/unicode.o +0 -0
  90. data/vendor/gems/gems/json-1.1.3/install.rb +0 -26
  91. data/vendor/gems/gems/json-1.1.3/lib/json.rb +0 -235
  92. data/vendor/gems/gems/json-1.1.3/lib/json/Array.xpm +0 -21
  93. data/vendor/gems/gems/json-1.1.3/lib/json/FalseClass.xpm +0 -21
  94. data/vendor/gems/gems/json-1.1.3/lib/json/Hash.xpm +0 -21
  95. data/vendor/gems/gems/json-1.1.3/lib/json/Key.xpm +0 -73
  96. data/vendor/gems/gems/json-1.1.3/lib/json/NilClass.xpm +0 -21
  97. data/vendor/gems/gems/json-1.1.3/lib/json/Numeric.xpm +0 -28
  98. data/vendor/gems/gems/json-1.1.3/lib/json/String.xpm +0 -96
  99. data/vendor/gems/gems/json-1.1.3/lib/json/TrueClass.xpm +0 -21
  100. data/vendor/gems/gems/json-1.1.3/lib/json/add/core.rb +0 -135
  101. data/vendor/gems/gems/json-1.1.3/lib/json/add/rails.rb +0 -58
  102. data/vendor/gems/gems/json-1.1.3/lib/json/common.rb +0 -354
  103. data/vendor/gems/gems/json-1.1.3/lib/json/editor.rb +0 -1362
  104. data/vendor/gems/gems/json-1.1.3/lib/json/ext.rb +0 -13
  105. data/vendor/gems/gems/json-1.1.3/lib/json/json.xpm +0 -1499
  106. data/vendor/gems/gems/json-1.1.3/lib/json/pure.rb +0 -75
  107. data/vendor/gems/gems/json-1.1.3/lib/json/pure/generator.rb +0 -394
  108. data/vendor/gems/gems/json-1.1.3/lib/json/pure/parser.rb +0 -259
  109. data/vendor/gems/gems/json-1.1.3/lib/json/version.rb +0 -9
  110. data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail1.json +0 -1
  111. data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail10.json +0 -1
  112. data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail11.json +0 -1
  113. data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail12.json +0 -1
  114. data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail13.json +0 -1
  115. data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail14.json +0 -1
  116. data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail18.json +0 -1
  117. data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail19.json +0 -1
  118. data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail2.json +0 -1
  119. data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail20.json +0 -1
  120. data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail21.json +0 -1
  121. data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail22.json +0 -1
  122. data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail23.json +0 -1
  123. data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail24.json +0 -1
  124. data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail25.json +0 -1
  125. data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail27.json +0 -2
  126. data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail28.json +0 -2
  127. data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail3.json +0 -1
  128. data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail4.json +0 -1
  129. data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail5.json +0 -1
  130. data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail6.json +0 -1
  131. data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail7.json +0 -1
  132. data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail8.json +0 -1
  133. data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail9.json +0 -1
  134. data/vendor/gems/gems/json-1.1.3/tests/fixtures/pass1.json +0 -56
  135. data/vendor/gems/gems/json-1.1.3/tests/fixtures/pass15.json +0 -1
  136. data/vendor/gems/gems/json-1.1.3/tests/fixtures/pass16.json +0 -1
  137. data/vendor/gems/gems/json-1.1.3/tests/fixtures/pass17.json +0 -1
  138. data/vendor/gems/gems/json-1.1.3/tests/fixtures/pass2.json +0 -1
  139. data/vendor/gems/gems/json-1.1.3/tests/fixtures/pass26.json +0 -1
  140. data/vendor/gems/gems/json-1.1.3/tests/fixtures/pass3.json +0 -6
  141. data/vendor/gems/gems/json-1.1.3/tests/runner.rb +0 -25
  142. data/vendor/gems/gems/json-1.1.3/tests/test_json.rb +0 -293
  143. data/vendor/gems/gems/json-1.1.3/tests/test_json_addition.rb +0 -161
  144. data/vendor/gems/gems/json-1.1.3/tests/test_json_fixtures.rb +0 -30
  145. data/vendor/gems/gems/json-1.1.3/tests/test_json_generate.rb +0 -100
  146. data/vendor/gems/gems/json-1.1.3/tests/test_json_rails.rb +0 -118
  147. data/vendor/gems/gems/json-1.1.3/tests/test_json_unicode.rb +0 -61
  148. data/vendor/gems/gems/json-1.1.3/tools/fuzz.rb +0 -140
  149. data/vendor/gems/gems/json-1.1.3/tools/server.rb +0 -62
  150. data/vendor/gems/gems/rest-client-1.0.1/README.rdoc +0 -151
  151. data/vendor/gems/gems/rest-client-1.0.1/Rakefile +0 -85
  152. data/vendor/gems/gems/rest-client-1.0.1/bin/restclient +0 -87
  153. data/vendor/gems/gems/rest-client-1.0.1/lib/rest_client.rb +0 -2
  154. data/vendor/gems/gems/rest-client-1.0.1/lib/restclient.rb +0 -93
  155. data/vendor/gems/gems/rest-client-1.0.1/lib/restclient/exceptions.rb +0 -84
  156. data/vendor/gems/gems/rest-client-1.0.1/lib/restclient/mixin/response.rb +0 -43
  157. data/vendor/gems/gems/rest-client-1.0.1/lib/restclient/raw_response.rb +0 -30
  158. data/vendor/gems/gems/rest-client-1.0.1/lib/restclient/request.rb +0 -236
  159. data/vendor/gems/gems/rest-client-1.0.1/lib/restclient/resource.rb +0 -146
  160. data/vendor/gems/gems/rest-client-1.0.1/lib/restclient/response.rb +0 -20
  161. data/vendor/gems/gems/rest-client-1.0.1/spec/base.rb +0 -4
  162. data/vendor/gems/gems/rest-client-1.0.1/spec/exceptions_spec.rb +0 -54
  163. data/vendor/gems/gems/rest-client-1.0.1/spec/mixin/response_spec.rb +0 -46
  164. data/vendor/gems/gems/rest-client-1.0.1/spec/raw_response_spec.rb +0 -17
  165. data/vendor/gems/gems/rest-client-1.0.1/spec/request_spec.rb +0 -462
  166. data/vendor/gems/gems/rest-client-1.0.1/spec/resource_spec.rb +0 -75
  167. data/vendor/gems/gems/rest-client-1.0.1/spec/response_spec.rb +0 -16
  168. data/vendor/gems/gems/rest-client-1.0.1/spec/restclient_spec.rb +0 -53
  169. data/vendor/gems/gems/simple-rss-1.2/LICENSE +0 -429
  170. data/vendor/gems/gems/simple-rss-1.2/README +0 -43
  171. data/vendor/gems/gems/simple-rss-1.2/Rakefile +0 -212
  172. data/vendor/gems/gems/simple-rss-1.2/lib/simple-rss.rb +0 -149
  173. data/vendor/gems/gems/simple-rss-1.2/test/base/base_test.rb +0 -51
  174. data/vendor/gems/gems/simple-rss-1.2/test/data/atom.xml +0 -45
  175. data/vendor/gems/gems/simple-rss-1.2/test/data/not-rss.xml +0 -8
  176. data/vendor/gems/gems/simple-rss-1.2/test/data/rss09.rdf +0 -79
  177. data/vendor/gems/gems/simple-rss-1.2/test/data/rss20.xml +0 -818
  178. data/vendor/gems/gems/simple-rss-1.2/test/test_helper.rb +0 -4
  179. data/vendor/gems/gems/wycats-moneta-0.6.0/LICENSE +0 -20
  180. data/vendor/gems/gems/wycats-moneta-0.6.0/README +0 -50
  181. data/vendor/gems/gems/wycats-moneta-0.6.0/Rakefile +0 -60
  182. data/vendor/gems/gems/wycats-moneta-0.6.0/TODO +0 -4
  183. data/vendor/gems/gems/wycats-moneta-0.6.0/lib/moneta.rb +0 -76
  184. data/vendor/gems/gems/wycats-moneta-0.6.0/lib/moneta/datamapper.rb +0 -117
  185. data/vendor/gems/gems/wycats-moneta-0.6.0/lib/moneta/file.rb +0 -91
  186. data/vendor/gems/gems/wycats-moneta-0.6.0/lib/moneta/memcache.rb +0 -52
  187. data/vendor/gems/gems/wycats-moneta-0.6.0/lib/moneta/memory.rb +0 -11
  188. data/vendor/gems/gems/wycats-moneta-0.6.0/lib/moneta/xattr.rb +0 -58
  189. data/vendor/gems/specifications/crack-0.1.1.gemspec +0 -29
  190. data/vendor/gems/specifications/fakeweb-1.2.5.gemspec +0 -34
  191. data/vendor/gems/specifications/json-1.1.3.gemspec +0 -33
  192. data/vendor/gems/specifications/rest-client-1.0.1.gemspec +0 -30
  193. data/vendor/gems/specifications/simple-rss-1.2.gemspec +0 -27
  194. data/vendor/gems/specifications/wycats-moneta-0.6.0.gemspec +0 -29
@@ -1,20 +0,0 @@
1
- require File.dirname(__FILE__) + '/mixin/response'
2
-
3
- module RestClient
4
- # The response from RestClient looks like a string, but is actually one of
5
- # these. 99% of the time you're making a rest call all you care about is
6
- # the body, but on the occassion you want to fetch the headers you can:
7
- #
8
- # RestClient.get('http://example.com').headers[:content_type]
9
- #
10
- class Response < String
11
-
12
- include RestClient::Mixin::Response
13
-
14
- def initialize(string, net_http_res)
15
- @net_http_res = net_http_res
16
- super(string || "")
17
- end
18
-
19
- end
20
- end
@@ -1,4 +0,0 @@
1
- require 'rubygems'
2
- require 'spec'
3
-
4
- require File.dirname(__FILE__) + '/../lib/restclient'
@@ -1,54 +0,0 @@
1
- require File.dirname(__FILE__) + '/base'
2
-
3
- describe RestClient::Exception do
4
- it "sets the exception message to ErrorMessage" do
5
- RestClient::ResourceNotFound.new.message.should == 'Resource not found'
6
- end
7
-
8
- it "contains exceptions in RestClient" do
9
- RestClient::Unauthorized.new.should be_a_kind_of(RestClient::Exception)
10
- RestClient::ServerBrokeConnection.new.should be_a_kind_of(RestClient::Exception)
11
- end
12
- end
13
-
14
- describe RestClient::RequestFailed do
15
- it "stores the http response on the exception" do
16
- begin
17
- raise RestClient::RequestFailed, :response
18
- rescue RestClient::RequestFailed => e
19
- e.response.should == :response
20
- end
21
- end
22
-
23
- it "http_code convenience method for fetching the code as an integer" do
24
- RestClient::RequestFailed.new(mock('res', :code => '502')).http_code.should == 502
25
- end
26
-
27
- it "shows the status code in the message" do
28
- RestClient::RequestFailed.new(mock('res', :code => '502')).to_s.should match(/502/)
29
- end
30
- end
31
-
32
- describe RestClient::ResourceNotFound do
33
- it "also has the http response attached" do
34
- begin
35
- raise RestClient::ResourceNotFound, :response
36
- rescue RestClient::ResourceNotFound => e
37
- e.response.should == :response
38
- end
39
- end
40
- end
41
-
42
- describe "backwards compatibility" do
43
- it "alias RestClient::Request::Redirect to RestClient::Redirect" do
44
- RestClient::Request::Redirect.should == RestClient::Redirect
45
- end
46
-
47
- it "alias RestClient::Request::Unauthorized to RestClient::Unauthorized" do
48
- RestClient::Request::Unauthorized.should == RestClient::Unauthorized
49
- end
50
-
51
- it "alias RestClient::Request::RequestFailed to RestClient::RequestFailed" do
52
- RestClient::Request::RequestFailed.should == RestClient::RequestFailed
53
- end
54
- end
@@ -1,46 +0,0 @@
1
- require File.dirname(__FILE__) + '/../base'
2
-
3
- class MockResponse
4
- include RestClient::Mixin::Response
5
-
6
- def initialize(body, res)
7
- @net_http_res = res
8
- @body = @body
9
- end
10
- end
11
-
12
- describe RestClient::Mixin::Response do
13
- before do
14
- @net_http_res = mock('net http response')
15
- @response = MockResponse.new('abc', @net_http_res)
16
- end
17
-
18
- it "fetches the numeric response code" do
19
- @net_http_res.should_receive(:code).and_return('200')
20
- @response.code.should == 200
21
- end
22
-
23
- it "beautifies the headers by turning the keys to symbols" do
24
- h = RestClient::Response.beautify_headers('content-type' => [ 'x' ])
25
- h.keys.first.should == :content_type
26
- end
27
-
28
- it "beautifies the headers by turning the values to strings instead of one-element arrays" do
29
- h = RestClient::Response.beautify_headers('x' => [ 'text/html' ] )
30
- h.values.first.should == 'text/html'
31
- end
32
-
33
- it "fetches the headers" do
34
- @net_http_res.should_receive(:to_hash).and_return('content-type' => [ 'text/html' ])
35
- @response.headers.should == { :content_type => 'text/html' }
36
- end
37
-
38
- it "extracts cookies from response headers" do
39
- @net_http_res.should_receive(:to_hash).and_return('set-cookie' => ['session_id=1; path=/'])
40
- @response.cookies.should == { 'session_id' => '1' }
41
- end
42
-
43
- it "can access the net http result directly" do
44
- @response.net_http_res.should == @net_http_res
45
- end
46
- end
@@ -1,17 +0,0 @@
1
- require File.dirname(__FILE__) + '/base'
2
-
3
- describe RestClient::RawResponse do
4
- before do
5
- @tf = mock("Tempfile", :read => "the answer is 42", :open => true)
6
- @net_http_res = mock('net http response')
7
- @response = RestClient::RawResponse.new(@tf, @net_http_res)
8
- end
9
-
10
- it "behaves like string" do
11
- @response.to_s.should == 'the answer is 42'
12
- end
13
-
14
- it "exposes a Tempfile" do
15
- @response.file.should == @tf
16
- end
17
- end
@@ -1,462 +0,0 @@
1
- require File.dirname(__FILE__) + '/base'
2
-
3
- describe RestClient::Request do
4
- before do
5
- @request = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload')
6
-
7
- @uri = mock("uri")
8
- @uri.stub!(:request_uri).and_return('/resource')
9
- @uri.stub!(:host).and_return('some')
10
- @uri.stub!(:port).and_return(80)
11
-
12
- @net = mock("net::http base")
13
- @http = mock("net::http connection")
14
- Net::HTTP.stub!(:new).and_return(@net)
15
- @net.stub!(:start).and_yield(@http)
16
- @net.stub!(:use_ssl=)
17
- @net.stub!(:verify_mode=)
18
- end
19
-
20
- it "requests xml mimetype" do
21
- @request.default_headers[:accept].should == 'application/xml'
22
- end
23
-
24
- it "decodes an uncompressed result body by passing it straight through" do
25
- @request.decode(nil, 'xyz').should == 'xyz'
26
- end
27
-
28
- it "decodes a gzip body" do
29
- @request.decode('gzip', "\037\213\b\b\006'\252H\000\003t\000\313T\317UH\257\312,HM\341\002\000G\242(\r\v\000\000\000").should == "i'm gziped\n"
30
- end
31
-
32
- it "ingores gzip for empty bodies" do
33
- @request.decode('gzip', '').should be_empty
34
- end
35
-
36
- it "decodes a deflated body" do
37
- @request.decode('deflate', "x\234+\316\317MUHIM\313I,IMQ(I\255(\001\000A\223\006\363").should == "some deflated text"
38
- end
39
-
40
- it "processes a successful result" do
41
- res = mock("result")
42
- res.stub!(:code).and_return("200")
43
- res.stub!(:body).and_return('body')
44
- res.stub!(:[]).with('content-encoding').and_return(nil)
45
- @request.process_result(res).should == 'body'
46
- end
47
-
48
- it "doesn't classify successful requests as failed" do
49
- 203.upto(206) do |code|
50
- res = mock("result")
51
- res.stub!(:code).and_return(code.to_s)
52
- res.stub!(:body).and_return("")
53
- res.stub!(:[]).with('content-encoding').and_return(nil)
54
- @request.process_result(res).should be_empty
55
- end
56
- end
57
-
58
- it "parses a url into a URI object" do
59
- URI.should_receive(:parse).with('http://example.com/resource')
60
- @request.parse_url('http://example.com/resource')
61
- end
62
-
63
- it "adds http:// to the front of resources specified in the syntax example.com/resource" do
64
- URI.should_receive(:parse).with('http://example.com/resource')
65
- @request.parse_url('example.com/resource')
66
- end
67
-
68
- it "extracts the username and password when parsing http://user:password@example.com/" do
69
- URI.stub!(:parse).and_return(mock('uri', :user => 'joe', :password => 'pass1'))
70
- @request.parse_url_with_auth('http://joe:pass1@example.com/resource')
71
- @request.user.should == 'joe'
72
- @request.password.should == 'pass1'
73
- end
74
-
75
- it "doesn't overwrite user and password (which may have already been set by the Resource constructor) if there is no user/password in the url" do
76
- URI.stub!(:parse).and_return(mock('uri', :user => nil, :password => nil))
77
- @request = RestClient::Request.new(:method => 'get', :url => 'example.com', :user => 'beth', :password => 'pass2')
78
- @request.parse_url_with_auth('http://example.com/resource')
79
- @request.user.should == 'beth'
80
- @request.password.should == 'pass2'
81
- end
82
-
83
- it "correctly formats cookies provided to the constructor" do
84
- URI.stub!(:parse).and_return(mock('uri', :user => nil, :password => nil))
85
- @request = RestClient::Request.new(:method => 'get', :url => 'example.com', :cookies => {:session_id => '1' })
86
- @request.should_receive(:default_headers).and_return({'foo' => 'bar'})
87
- headers = @request.make_headers({}).should == { 'Foo' => 'bar', 'Cookie' => 'session_id=1'}
88
- end
89
-
90
- it "determines the Net::HTTP class to instantiate by the method name" do
91
- @request.net_http_request_class(:put).should == Net::HTTP::Put
92
- end
93
-
94
- it "merges user headers with the default headers" do
95
- @request.should_receive(:default_headers).and_return({ '1' => '2' })
96
- @request.make_headers('3' => '4').should == { '1' => '2', '3' => '4' }
97
- end
98
-
99
- it "prefers the user header when the same header exists in the defaults" do
100
- @request.should_receive(:default_headers).and_return({ '1' => '2' })
101
- @request.make_headers('1' => '3').should == { '1' => '3' }
102
- end
103
-
104
- it "converts header symbols from :content_type to 'Content-type'" do
105
- @request.should_receive(:default_headers).and_return({})
106
- @request.make_headers(:content_type => 'abc').should == { 'Content-type' => 'abc' }
107
- end
108
-
109
- it "converts header values to strings" do
110
- @request.make_headers('A' => 1)['A'].should == '1'
111
- end
112
-
113
- it "executes by constructing the Net::HTTP object, headers, and payload and calling transmit" do
114
- @request.should_receive(:parse_url_with_auth).with('http://some/resource').and_return(@uri)
115
- klass = mock("net:http class")
116
- @request.should_receive(:net_http_request_class).with(:put).and_return(klass)
117
- klass.should_receive(:new).and_return('result')
118
- @request.should_receive(:transmit).with(@uri, 'result', 'payload')
119
- @request.execute_inner
120
- end
121
-
122
- it "transmits the request with Net::HTTP" do
123
- @http.should_receive(:request).with('req', 'payload')
124
- @request.should_receive(:process_result)
125
- @request.should_receive(:response_log)
126
- @request.transmit(@uri, 'req', 'payload')
127
- end
128
-
129
- it "uses SSL when the URI refers to a https address" do
130
- @uri.stub!(:is_a?).with(URI::HTTPS).and_return(true)
131
- @net.should_receive(:use_ssl=).with(true)
132
- @http.stub!(:request)
133
- @request.stub!(:process_result)
134
- @request.stub!(:response_log)
135
- @request.transmit(@uri, 'req', 'payload')
136
- end
137
-
138
- it "sends nil payloads" do
139
- @http.should_receive(:request).with('req', nil)
140
- @request.should_receive(:process_result)
141
- @request.stub!(:response_log)
142
- @request.transmit(@uri, 'req', nil)
143
- end
144
-
145
- it "passes non-hash payloads straight through" do
146
- @request.process_payload("x").should == "x"
147
- end
148
-
149
- it "converts a hash payload to urlencoded data" do
150
- @request.process_payload(:a => 'b c+d').should == "a=b%20c%2Bd"
151
- end
152
-
153
- it "accepts nested hashes in payload" do
154
- payload = @request.process_payload(:user => { :name => 'joe', :location => { :country => 'USA', :state => 'CA' }})
155
- payload.should include('user[name]=joe')
156
- payload.should include('user[location][country]=USA')
157
- payload.should include('user[location][state]=CA')
158
- end
159
-
160
- it "set urlencoded content_type header on hash payloads" do
161
- @request.process_payload(:a => 1)
162
- @request.headers[:content_type].should == 'application/x-www-form-urlencoded'
163
- end
164
-
165
- it "sets up the credentials prior to the request" do
166
- @http.stub!(:request)
167
- @request.stub!(:process_result)
168
- @request.stub!(:response_log)
169
-
170
- @request.stub!(:user).and_return('joe')
171
- @request.stub!(:password).and_return('mypass')
172
- @request.should_receive(:setup_credentials).with('req')
173
-
174
- @request.transmit(@uri, 'req', nil)
175
- end
176
-
177
- it "does not attempt to send any credentials if user is nil" do
178
- @request.stub!(:user).and_return(nil)
179
- req = mock("request")
180
- req.should_not_receive(:basic_auth)
181
- @request.setup_credentials(req)
182
- end
183
-
184
- it "setup credentials when there's a user" do
185
- @request.stub!(:user).and_return('joe')
186
- @request.stub!(:password).and_return('mypass')
187
- req = mock("request")
188
- req.should_receive(:basic_auth).with('joe', 'mypass')
189
- @request.setup_credentials(req)
190
- end
191
-
192
- it "catches EOFError and shows the more informative ServerBrokeConnection" do
193
- @http.stub!(:request).and_raise(EOFError)
194
- lambda { @request.transmit(@uri, 'req', nil) }.should raise_error(RestClient::ServerBrokeConnection)
195
- end
196
-
197
- it "execute calls execute_inner" do
198
- @request.should_receive(:execute_inner)
199
- @request.execute
200
- end
201
-
202
- it "class method execute wraps constructor" do
203
- req = mock("rest request")
204
- RestClient::Request.should_receive(:new).with(1 => 2).and_return(req)
205
- req.should_receive(:execute)
206
- RestClient::Request.execute(1 => 2)
207
- end
208
-
209
- it "raises a Redirect with the new location when the response is in the 30x range" do
210
- res = mock('response', :code => '301', :header => { 'Location' => 'http://new/resource' })
211
- lambda { @request.process_result(res) }.should raise_error(RestClient::Redirect) { |e| e.url.should == 'http://new/resource'}
212
- end
213
-
214
- it "handles redirects with relative paths" do
215
- res = mock('response', :code => '301', :header => { 'Location' => 'index' })
216
- lambda { @request.process_result(res) }.should raise_error(RestClient::Redirect) { |e| e.url.should == 'http://some/index' }
217
- end
218
-
219
- it "handles redirects with absolute paths" do
220
- @request.instance_variable_set('@url', 'http://some/place/else')
221
- res = mock('response', :code => '301', :header => { 'Location' => '/index' })
222
- lambda { @request.process_result(res) }.should raise_error(RestClient::Redirect) { |e| e.url.should == 'http://some/index' }
223
- end
224
-
225
- it "raises Unauthorized when the response is 401" do
226
- res = mock('response', :code => '401')
227
- lambda { @request.process_result(res) }.should raise_error(RestClient::Unauthorized)
228
- end
229
-
230
- it "raises ResourceNotFound when the response is 404" do
231
- res = mock('response', :code => '404')
232
- lambda { @request.process_result(res) }.should raise_error(RestClient::ResourceNotFound)
233
- end
234
-
235
- it "raises RequestFailed otherwise" do
236
- res = mock('response', :code => '500')
237
- lambda { @request.process_result(res) }.should raise_error(RestClient::RequestFailed)
238
- end
239
-
240
- it "creates a proxy class if a proxy url is given" do
241
- RestClient.stub!(:proxy).and_return("http://example.com/")
242
- @request.net_http_class.should include(Net::HTTP::ProxyDelta)
243
- end
244
-
245
- it "creates a non-proxy class if a proxy url is not given" do
246
- @request.net_http_class.should_not include(Net::HTTP::ProxyDelta)
247
- end
248
-
249
- it "logs a get request" do
250
- RestClient::Request.new(:method => :get, :url => 'http://url').request_log.should ==
251
- 'RestClient.get "http://url"'
252
- end
253
-
254
- it "logs a post request with a small payload" do
255
- RestClient::Request.new(:method => :post, :url => 'http://url', :payload => 'foo').request_log.should ==
256
- 'RestClient.post "http://url", "foo"'
257
- end
258
-
259
- it "logs a post request with a large payload" do
260
- RestClient::Request.new(:method => :post, :url => 'http://url', :payload => ('x' * 1000)).request_log.should ==
261
- 'RestClient.post "http://url", "(1000 byte payload)"'
262
- end
263
-
264
- it "logs input headers as a hash" do
265
- RestClient::Request.new(:method => :get, :url => 'http://url', :headers => { :accept => 'text/plain' }).request_log.should ==
266
- 'RestClient.get "http://url", :accept=>"text/plain"'
267
- end
268
-
269
- it "logs a response including the status code, content type, and result body size in bytes" do
270
- res = mock('result', :code => '200', :class => Net::HTTPOK, :body => 'abcd')
271
- res.stub!(:[]).with('Content-type').and_return('text/html')
272
- @request.response_log(res).should == "# => 200 OK | text/html 4 bytes"
273
- end
274
-
275
- it "logs a response with a nil Content-type" do
276
- res = mock('result', :code => '200', :class => Net::HTTPOK, :body => 'abcd')
277
- res.stub!(:[]).with('Content-type').and_return(nil)
278
- @request.response_log(res).should == "# => 200 OK | 4 bytes"
279
- end
280
-
281
- it "logs a response with a nil body" do
282
- res = mock('result', :code => '200', :class => Net::HTTPOK, :body => nil)
283
- res.stub!(:[]).with('Content-type').and_return('text/html; charset=utf-8')
284
- @request.response_log(res).should == "# => 200 OK | text/html 0 bytes"
285
- end
286
-
287
- it "strips the charset from the response content type" do
288
- res = mock('result', :code => '200', :class => Net::HTTPOK, :body => 'abcd')
289
- res.stub!(:[]).with('Content-type').and_return('text/html; charset=utf-8')
290
- @request.response_log(res).should == "# => 200 OK | text/html 4 bytes"
291
- end
292
-
293
- it "displays the log to stdout" do
294
- RestClient.stub!(:log).and_return('stdout')
295
- STDOUT.should_receive(:puts).with('xyz')
296
- @request.display_log('xyz')
297
- end
298
-
299
- it "displays the log to stderr" do
300
- RestClient.stub!(:log).and_return('stderr')
301
- STDERR.should_receive(:puts).with('xyz')
302
- @request.display_log('xyz')
303
- end
304
-
305
- it "append the log to the requested filename" do
306
- RestClient.stub!(:log).and_return('/tmp/restclient.log')
307
- f = mock('file handle')
308
- File.should_receive(:open).with('/tmp/restclient.log', 'a').and_yield(f)
309
- f.should_receive(:puts).with('xyz')
310
- @request.display_log('xyz')
311
- end
312
-
313
- it "set read_timeout" do
314
- @request = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload', :timeout => 123)
315
- @http.stub!(:request)
316
- @request.stub!(:process_result)
317
- @request.stub!(:response_log)
318
-
319
- @net.should_receive(:read_timeout=).with(123)
320
-
321
- @request.transmit(@uri, 'req', nil)
322
- end
323
-
324
- it "set open_timeout" do
325
- @request = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload', :open_timeout => 123)
326
- @http.stub!(:request)
327
- @request.stub!(:process_result)
328
- @request.stub!(:response_log)
329
-
330
- @net.should_receive(:open_timeout=).with(123)
331
-
332
- @request.transmit(@uri, 'req', nil)
333
- end
334
-
335
- it "should default to not verifying ssl certificates" do
336
- @request.verify_ssl.should == false
337
- end
338
-
339
- it "should set net.verify_mode to OpenSSL::SSL::VERIFY_NONE if verify_ssl is false" do
340
- @net.should_receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
341
- @http.stub!(:request)
342
- @request.stub!(:process_result)
343
- @request.stub!(:response_log)
344
- @request.transmit(@uri, 'req', 'payload')
345
- end
346
-
347
- it "should not set net.verify_mode to OpenSSL::SSL::VERIFY_NONE if verify_ssl is true" do
348
- @request = RestClient::Request.new(:method => :put, :url => 'https://some/resource', :payload => 'payload', :verify_ssl => true)
349
- @net.should_not_receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
350
- @http.stub!(:request)
351
- @request.stub!(:process_result)
352
- @request.stub!(:response_log)
353
- @request.transmit(@uri, 'req', 'payload')
354
- end
355
-
356
- it "should set net.verify_mode to the passed value if verify_ssl is an OpenSSL constant" do
357
- mode = OpenSSL::SSL::VERIFY_PEER |
358
- OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT
359
- @request = RestClient::Request.new( :method => :put,
360
- :url => 'https://some/resource',
361
- :payload => 'payload',
362
- :verify_ssl => mode )
363
- @net.should_receive(:verify_mode=).with(mode)
364
- @http.stub!(:request)
365
- @request.stub!(:process_result)
366
- @request.stub!(:response_log)
367
- @request.transmit(@uri, 'req', 'payload')
368
- end
369
-
370
- it "should default to not having an ssl_client_cert" do
371
- @request.ssl_client_cert.should be(nil)
372
- end
373
-
374
- it "should set the ssl_client_cert if provided" do
375
- @request = RestClient::Request.new(
376
- :method => :put,
377
- :url => 'https://some/resource',
378
- :payload => 'payload',
379
- :ssl_client_cert => "whatsupdoc!"
380
- )
381
- @net.should_receive(:cert=).with("whatsupdoc!")
382
- @http.stub!(:request)
383
- @request.stub!(:process_result)
384
- @request.stub!(:response_log)
385
- @request.transmit(@uri, 'req', 'payload')
386
- end
387
-
388
- it "should not set the ssl_client_cert if it is not provided" do
389
- @request = RestClient::Request.new(
390
- :method => :put,
391
- :url => 'https://some/resource',
392
- :payload => 'payload'
393
- )
394
- @net.should_not_receive(:cert=).with("whatsupdoc!")
395
- @http.stub!(:request)
396
- @request.stub!(:process_result)
397
- @request.stub!(:response_log)
398
- @request.transmit(@uri, 'req', 'payload')
399
- end
400
-
401
- it "should default to not having an ssl_client_key" do
402
- @request.ssl_client_key.should be(nil)
403
- end
404
-
405
- it "should set the ssl_client_key if provided" do
406
- @request = RestClient::Request.new(
407
- :method => :put,
408
- :url => 'https://some/resource',
409
- :payload => 'payload',
410
- :ssl_client_key => "whatsupdoc!"
411
- )
412
- @net.should_receive(:key=).with("whatsupdoc!")
413
- @http.stub!(:request)
414
- @request.stub!(:process_result)
415
- @request.stub!(:response_log)
416
- @request.transmit(@uri, 'req', 'payload')
417
- end
418
-
419
- it "should not set the ssl_client_key if it is not provided" do
420
- @request = RestClient::Request.new(
421
- :method => :put,
422
- :url => 'https://some/resource',
423
- :payload => 'payload'
424
- )
425
- @net.should_not_receive(:key=).with("whatsupdoc!")
426
- @http.stub!(:request)
427
- @request.stub!(:process_result)
428
- @request.stub!(:response_log)
429
- @request.transmit(@uri, 'req', 'payload')
430
- end
431
-
432
- it "should default to not having an ssl_ca_file" do
433
- @request.ssl_ca_file.should be(nil)
434
- end
435
-
436
- it "should set the ssl_ca_file if provided" do
437
- @request = RestClient::Request.new(
438
- :method => :put,
439
- :url => 'https://some/resource',
440
- :payload => 'payload',
441
- :ssl_ca_file => "Certificate Authority File"
442
- )
443
- @net.should_receive(:ca_file=).with("Certificate Authority File")
444
- @http.stub!(:request)
445
- @request.stub!(:process_result)
446
- @request.stub!(:response_log)
447
- @request.transmit(@uri, 'req', 'payload')
448
- end
449
-
450
- it "should not set the ssl_ca_file if it is not provided" do
451
- @request = RestClient::Request.new(
452
- :method => :put,
453
- :url => 'https://some/resource',
454
- :payload => 'payload'
455
- )
456
- @net.should_not_receive(:ca_file=).with("Certificate Authority File")
457
- @http.stub!(:request)
458
- @request.stub!(:process_result)
459
- @request.stub!(:response_log)
460
- @request.transmit(@uri, 'req', 'payload')
461
- end
462
- end