rubysl-net-http 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +0 -1
  3. data/.travis.yml +7 -0
  4. data/README.md +2 -2
  5. data/Rakefile +0 -1
  6. data/lib/net/http.rb +1 -0
  7. data/lib/rubysl/net/http.rb +2 -0
  8. data/lib/rubysl/net/http/http.rb +2290 -0
  9. data/lib/rubysl/net/http/https.rb +173 -0
  10. data/lib/{rubysl-net-http → rubysl/net/http}/version.rb +2 -2
  11. data/rubysl-net-http.gemspec +18 -18
  12. data/spec/HTTPBadResponse_spec.rb +7 -0
  13. data/spec/HTTPError_spec.rb +11 -0
  14. data/spec/HTTPFatalError_spec.rb +11 -0
  15. data/spec/HTTPHeaderSyntaxError_spec.rb +7 -0
  16. data/spec/HTTPRetriableError_spec.rb +11 -0
  17. data/spec/HTTPServerException_spec.rb +11 -0
  18. data/spec/http/Proxy_spec.rb +34 -0
  19. data/spec/http/active_spec.rb +7 -0
  20. data/spec/http/address_spec.rb +8 -0
  21. data/spec/http/close_on_empty_response_spec.rb +9 -0
  22. data/spec/http/copy_spec.rb +26 -0
  23. data/spec/http/default_port_spec.rb +7 -0
  24. data/spec/http/delete_spec.rb +26 -0
  25. data/spec/http/finish_spec.rb +30 -0
  26. data/spec/http/fixtures/http_server.rb +97 -0
  27. data/spec/http/get2_spec.rb +7 -0
  28. data/spec/http/get_print_spec.rb +28 -0
  29. data/spec/http/get_response_spec.rb +28 -0
  30. data/spec/http/get_spec.rb +52 -0
  31. data/spec/http/head2_spec.rb +8 -0
  32. data/spec/http/head_spec.rb +30 -0
  33. data/spec/http/http_default_port_spec.rb +7 -0
  34. data/spec/http/https_default_port_spec.rb +7 -0
  35. data/spec/http/initialize_spec.rb +45 -0
  36. data/spec/http/inspect_spec.rb +25 -0
  37. data/spec/http/is_version_1_1_spec.rb +6 -0
  38. data/spec/http/is_version_1_2_spec.rb +6 -0
  39. data/spec/http/lock_spec.rb +26 -0
  40. data/spec/http/mkcol_spec.rb +26 -0
  41. data/spec/http/move_spec.rb +30 -0
  42. data/spec/http/new_spec.rb +96 -0
  43. data/spec/http/newobj_spec.rb +47 -0
  44. data/spec/http/open_timeout_spec.rb +23 -0
  45. data/spec/http/options_spec.rb +30 -0
  46. data/spec/http/port_spec.rb +8 -0
  47. data/spec/http/post2_spec.rb +7 -0
  48. data/spec/http/post_form_spec.rb +20 -0
  49. data/spec/http/post_spec.rb +43 -0
  50. data/spec/http/propfind_spec.rb +29 -0
  51. data/spec/http/proppatch_spec.rb +29 -0
  52. data/spec/http/proxy_address_spec.rb +30 -0
  53. data/spec/http/proxy_class_spec.rb +8 -0
  54. data/spec/http/proxy_pass_spec.rb +38 -0
  55. data/spec/http/proxy_port_spec.rb +38 -0
  56. data/spec/http/proxy_user_spec.rb +38 -0
  57. data/spec/http/put2_spec.rb +7 -0
  58. data/spec/http/put_spec.rb +29 -0
  59. data/spec/http/read_timeout_spec.rb +23 -0
  60. data/spec/http/request_get_spec.rb +7 -0
  61. data/spec/http/request_head_spec.rb +7 -0
  62. data/spec/http/request_post_spec.rb +7 -0
  63. data/spec/http/request_put_spec.rb +7 -0
  64. data/spec/http/request_spec.rb +114 -0
  65. data/spec/http/request_types_spec.rb +253 -0
  66. data/spec/http/send_request_spec.rb +123 -0
  67. data/spec/http/set_debug_output_spec.rb +34 -0
  68. data/spec/http/shared/request_get.rb +49 -0
  69. data/spec/http/shared/request_head.rb +49 -0
  70. data/spec/http/shared/request_post.rb +49 -0
  71. data/spec/http/shared/request_put.rb +49 -0
  72. data/spec/http/shared/started.rb +28 -0
  73. data/spec/http/shared/version_1_1.rb +19 -0
  74. data/spec/http/shared/version_1_2.rb +6 -0
  75. data/spec/http/socket_type_spec.rb +7 -0
  76. data/spec/http/start_spec.rb +115 -0
  77. data/spec/http/started_spec.rb +7 -0
  78. data/spec/http/trace_spec.rb +29 -0
  79. data/spec/http/unlock_spec.rb +29 -0
  80. data/spec/http/use_ssl_spec.rb +8 -0
  81. data/spec/http/version_1_1_spec.rb +21 -0
  82. data/spec/http/version_1_2_spec.rb +19 -0
  83. data/spec/httpexceptions/fixtures/classes.rb +5 -0
  84. data/spec/httpexceptions/initialize_spec.rb +16 -0
  85. data/spec/httpexceptions/response_spec.rb +9 -0
  86. data/spec/httpgenericrequest/body_exist_spec.rb +26 -0
  87. data/spec/httpgenericrequest/body_spec.rb +29 -0
  88. data/spec/httpgenericrequest/body_stream_spec.rb +31 -0
  89. data/spec/httpgenericrequest/exec_spec.rb +135 -0
  90. data/spec/httpgenericrequest/inspect_spec.rb +24 -0
  91. data/spec/httpgenericrequest/method_spec.rb +14 -0
  92. data/spec/httpgenericrequest/path_spec.rb +11 -0
  93. data/spec/httpgenericrequest/request_body_permitted_spec.rb +11 -0
  94. data/spec/httpgenericrequest/response_body_permitted_spec.rb +11 -0
  95. data/spec/httpgenericrequest/set_body_internal_spec.rb +20 -0
  96. data/spec/httpheader/add_field_spec.rb +30 -0
  97. data/spec/httpheader/basic_auth_spec.rb +13 -0
  98. data/spec/httpheader/canonical_each_spec.rb +7 -0
  99. data/spec/httpheader/chunked_spec.rb +21 -0
  100. data/spec/httpheader/content_length_spec.rb +53 -0
  101. data/spec/httpheader/content_range_spec.rb +33 -0
  102. data/spec/httpheader/content_type_spec.rb +25 -0
  103. data/spec/httpheader/delete_spec.rb +29 -0
  104. data/spec/httpheader/each_capitalized_name_spec.rb +44 -0
  105. data/spec/httpheader/each_capitalized_spec.rb +8 -0
  106. data/spec/httpheader/each_header_spec.rb +7 -0
  107. data/spec/httpheader/each_key_spec.rb +7 -0
  108. data/spec/httpheader/each_name_spec.rb +7 -0
  109. data/spec/httpheader/each_spec.rb +7 -0
  110. data/spec/httpheader/each_value_spec.rb +45 -0
  111. data/spec/httpheader/element_reference_spec.rb +38 -0
  112. data/spec/httpheader/element_set_spec.rb +40 -0
  113. data/spec/httpheader/fetch_spec.rb +68 -0
  114. data/spec/httpheader/fixtures/classes.rb +11 -0
  115. data/spec/httpheader/form_data_spec.rb +7 -0
  116. data/spec/httpheader/get_fields_spec.rb +38 -0
  117. data/spec/httpheader/initialize_http_header_spec.rb +28 -0
  118. data/spec/httpheader/key_spec.rb +20 -0
  119. data/spec/httpheader/length_spec.rb +7 -0
  120. data/spec/httpheader/main_type_spec.rb +23 -0
  121. data/spec/httpheader/proxy_basic_auth_spec.rb +13 -0
  122. data/spec/httpheader/range_length_spec.rb +31 -0
  123. data/spec/httpheader/range_spec.rb +47 -0
  124. data/spec/httpheader/set_content_type_spec.rb +7 -0
  125. data/spec/httpheader/set_form_data_spec.rb +7 -0
  126. data/spec/httpheader/set_range_spec.rb +7 -0
  127. data/spec/httpheader/shared/each_capitalized.rb +42 -0
  128. data/spec/httpheader/shared/each_header.rb +42 -0
  129. data/spec/httpheader/shared/each_name.rb +39 -0
  130. data/spec/httpheader/shared/set_content_type.rb +20 -0
  131. data/spec/httpheader/shared/set_form_data.rb +27 -0
  132. data/spec/httpheader/shared/set_range.rb +89 -0
  133. data/spec/httpheader/shared/size.rb +18 -0
  134. data/spec/httpheader/size_spec.rb +7 -0
  135. data/spec/httpheader/sub_type_spec.rb +31 -0
  136. data/spec/httpheader/to_hash_spec.rb +24 -0
  137. data/spec/httpheader/type_params_spec.rb +23 -0
  138. data/spec/httprequest/initialize_spec.rb +44 -0
  139. data/spec/httpresponse/body_permitted_spec.rb +12 -0
  140. data/spec/httpresponse/body_spec.rb +6 -0
  141. data/spec/httpresponse/code_spec.rb +23 -0
  142. data/spec/httpresponse/code_type_spec.rb +23 -0
  143. data/spec/httpresponse/entity_spec.rb +6 -0
  144. data/spec/httpresponse/error_spec.rb +23 -0
  145. data/spec/httpresponse/error_type_spec.rb +23 -0
  146. data/spec/httpresponse/exception_type_spec.rb +12 -0
  147. data/spec/httpresponse/header_spec.rb +8 -0
  148. data/spec/httpresponse/http_version_spec.rb +11 -0
  149. data/spec/httpresponse/initialize_spec.rb +10 -0
  150. data/spec/httpresponse/inspect_spec.rb +14 -0
  151. data/spec/httpresponse/message_spec.rb +8 -0
  152. data/spec/httpresponse/msg_spec.rb +8 -0
  153. data/spec/httpresponse/read_body_spec.rb +85 -0
  154. data/spec/httpresponse/read_header_spec.rb +8 -0
  155. data/spec/httpresponse/read_new_spec.rb +21 -0
  156. data/spec/httpresponse/reading_body_spec.rb +57 -0
  157. data/spec/httpresponse/response_spec.rb +8 -0
  158. data/spec/httpresponse/shared/body.rb +18 -0
  159. data/spec/httpresponse/to_ary_spec.rb +25 -0
  160. data/spec/httpresponse/value_spec.rb +23 -0
  161. metadata +366 -88
  162. data/lib/rubysl-net-http.rb +0 -9
@@ -0,0 +1,11 @@
1
+ require 'net/http'
2
+
3
+ describe "Net::HTTPGenericRequest#response_body_permitted?" do
4
+ it "returns true when the response is expected to have a body" do
5
+ request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
6
+ request.response_body_permitted?.should be_true
7
+
8
+ request = Net::HTTPGenericRequest.new("POST", true, false, "/some/path")
9
+ request.response_body_permitted?.should be_false
10
+ end
11
+ end
@@ -0,0 +1,20 @@
1
+ require 'net/http'
2
+
3
+ describe "Net::HTTPGenericRequest#set_body_internal when passed string" do
4
+ before(:each) do
5
+ @request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
6
+ end
7
+
8
+ it "sets self's body to the passed string" do
9
+ @request.set_body_internal("Some Content")
10
+ @request.body.should == "Some Content"
11
+ end
12
+
13
+ it "raises an ArgumentError when the body or body_stream of self have already been set" do
14
+ @request.body = "Some Content"
15
+ lambda { @request.set_body_internal("Some other Content") }.should raise_error(ArgumentError)
16
+
17
+ @request.body_stream = "Some Content"
18
+ lambda { @request.set_body_internal("Some other Content") }.should raise_error(ArgumentError)
19
+ end
20
+ end
@@ -0,0 +1,30 @@
1
+ require 'net/http'
2
+ require File.expand_path('../fixtures/classes', __FILE__)
3
+
4
+ describe "Net::HTTPHeader#add_field when passed key, value" do
5
+ before(:each) do
6
+ @headers = NetHTTPHeaderSpecs::Example.new
7
+ end
8
+
9
+ it "adds the passed value to the header entry with the passed key" do
10
+ @headers.add_field("My-Header", "a")
11
+ @headers.get_fields("My-Header").should == ["a"]
12
+
13
+ @headers.add_field("My-Header", "b")
14
+ @headers.get_fields("My-Header").should == ["a", "b"]
15
+
16
+ @headers.add_field("My-Header", "c")
17
+ @headers.get_fields("My-Header").should == ["a", "b", "c"]
18
+ end
19
+
20
+ it "is case-insensitive" do
21
+ @headers.add_field("My-Header", "a")
22
+ @headers.get_fields("My-Header").should == ["a"]
23
+
24
+ @headers.add_field("my-header", "b")
25
+ @headers.get_fields("My-Header").should == ["a", "b"]
26
+
27
+ @headers.add_field("MY-HEADER", "c")
28
+ @headers.get_fields("My-Header").should == ["a", "b", "c"]
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ require 'net/http'
2
+ require File.expand_path('../fixtures/classes', __FILE__)
3
+
4
+ describe "Net::HTTPHeader#basic_auth when passed account, password" do
5
+ before(:each) do
6
+ @headers = NetHTTPHeaderSpecs::Example.new
7
+ end
8
+
9
+ it "sets the 'Authorization' Header entry for basic authorization" do
10
+ @headers.basic_auth("rubyspec", "rocks")
11
+ @headers["Authorization"].should == "Basic cnVieXNwZWM6cm9ja3M="
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ require 'net/http'
2
+ require File.expand_path('../fixtures/classes', __FILE__)
3
+ require File.expand_path('../shared/each_capitalized', __FILE__)
4
+
5
+ describe "Net::HTTPHeader#canonical_each" do
6
+ it_behaves_like :net_httpheader_each_capitalized, :canonical_each
7
+ end
@@ -0,0 +1,21 @@
1
+ require 'net/http'
2
+ require File.expand_path('../fixtures/classes', __FILE__)
3
+
4
+ describe "Net::HTTPHeader#chunked?" do
5
+ before(:each) do
6
+ @headers = NetHTTPHeaderSpecs::Example.new
7
+ end
8
+
9
+ it "returns true if the 'Transfer-Encoding' header entry is set to chunked" do
10
+ @headers.chunked?.should be_false
11
+
12
+ @headers["Transfer-Encoding"] = "bla"
13
+ @headers.chunked?.should be_false
14
+
15
+ @headers["Transfer-Encoding"] = "blachunkedbla"
16
+ @headers.chunked?.should be_false
17
+
18
+ @headers["Transfer-Encoding"] = "chunked"
19
+ @headers.chunked?.should be_true
20
+ end
21
+ end
@@ -0,0 +1,53 @@
1
+ require 'net/http'
2
+ require File.expand_path('../fixtures/classes', __FILE__)
3
+
4
+ describe "Net::HTTPHeader#content_length" do
5
+ before(:each) do
6
+ @headers = NetHTTPHeaderSpecs::Example.new
7
+ end
8
+
9
+ it "returns nil if no 'Content-Length' header entry is set" do
10
+ @headers.content_length.should be_nil
11
+ end
12
+
13
+ it "raises a Net::HTTPHeaderSyntaxError when the 'Content-Length' header entry has an invalid format" do
14
+ @headers["Content-Length"] = "invalid"
15
+ lambda { @headers.content_length }.should raise_error(Net::HTTPHeaderSyntaxError)
16
+ end
17
+
18
+ it "returns the value of the 'Content-Length' header entry as an Integer" do
19
+ @headers["Content-Length"] = "123"
20
+ @headers.content_length.should eql(123)
21
+
22
+ @headers["Content-Length"] = "123valid"
23
+ @headers.content_length.should eql(123)
24
+
25
+ @headers["Content-Length"] = "valid123"
26
+ @headers.content_length.should eql(123)
27
+ end
28
+ end
29
+
30
+ describe "Net::HTTPHeader#content_length=" do
31
+ before(:each) do
32
+ @headers = NetHTTPHeaderSpecs::Example.new
33
+ end
34
+
35
+ it "removes the 'Content-Length' entry if passed false or nil" do
36
+ @headers["Content-Length"] = "123"
37
+ @headers.content_length = nil
38
+ @headers["Content-Lenght"].should be_nil
39
+ end
40
+
41
+ it "sets the 'Content-Length' entry to the passed value" do
42
+ @headers.content_length = "123"
43
+ @headers["Content-Length"].should == "123"
44
+
45
+ @headers.content_length = "123valid"
46
+ @headers["Content-Length"].should == "123"
47
+ end
48
+
49
+ it "sets the 'Content-Length' entry to 0 if the passed value is not valid" do
50
+ @headers.content_length = "invalid123"
51
+ @headers["Content-Length"].should == "0"
52
+ end
53
+ end
@@ -0,0 +1,33 @@
1
+ require 'net/http'
2
+ require File.expand_path('../fixtures/classes', __FILE__)
3
+
4
+ describe "Net::HTTPHeader#content_range" do
5
+ before(:each) do
6
+ @headers = NetHTTPHeaderSpecs::Example.new
7
+ end
8
+
9
+ ruby_bug "[ruby-dev:40295]", "1.8.8" do
10
+ it "returns a Range object that represents the 'Content-Range' header entry" do
11
+ @headers["Content-Range"] = "bytes 0-499/1234"
12
+ @headers.content_range.should == (0..499)
13
+
14
+ @headers["Content-Range"] = "bytes 500-1233/1234"
15
+ @headers.content_range.should == (500..1233)
16
+ end
17
+ end
18
+
19
+ it "returns nil when there is no 'Content-Range' header entry" do
20
+ @headers.content_range.should be_nil
21
+ end
22
+
23
+ it "raises a Net::HTTPHeaderSyntaxError when the 'Content-Range' has an invalid format" do
24
+ @headers["Content-Range"] = "invalid"
25
+ lambda { @headers.content_range }.should raise_error(Net::HTTPHeaderSyntaxError)
26
+
27
+ @headers["Content-Range"] = "bytes 123-abc"
28
+ lambda { @headers.content_range }.should raise_error(Net::HTTPHeaderSyntaxError)
29
+
30
+ @headers["Content-Range"] = "bytes abc-123"
31
+ lambda { @headers.content_range }.should raise_error(Net::HTTPHeaderSyntaxError)
32
+ end
33
+ end
@@ -0,0 +1,25 @@
1
+ require 'net/http'
2
+ require File.expand_path('../fixtures/classes', __FILE__)
3
+ require File.expand_path('../shared/set_content_type', __FILE__)
4
+
5
+ describe "Net::HTTPHeader#content_type" do
6
+ before(:each) do
7
+ @headers = NetHTTPHeaderSpecs::Example.new
8
+ end
9
+
10
+ it "returns the content type string, as per 'Content-Type' header entry" do
11
+ @headers["Content-Type"] = "text/html"
12
+ @headers.content_type.should == "text/html"
13
+
14
+ @headers["Content-Type"] = "text/html;charset=utf-8"
15
+ @headers.content_type.should == "text/html"
16
+ end
17
+
18
+ it "returns nil if the 'Content-Type' header entry does not exist" do
19
+ @headers.content_type.should be_nil
20
+ end
21
+ end
22
+
23
+ describe "Net::HTTPHeader#content_type=" do
24
+ it_behaves_like :net_httpheader_set_content_type, :content_type=
25
+ end
@@ -0,0 +1,29 @@
1
+ require 'net/http'
2
+ require File.expand_path('../fixtures/classes', __FILE__)
3
+
4
+ describe "Net::HTTPHeader#delete when passed key" do
5
+ before(:each) do
6
+ @headers = NetHTTPHeaderSpecs::Example.new
7
+ end
8
+
9
+ it "removes the header entry with the passed key" do
10
+ @headers["My-Header"] = "test"
11
+ @headers.delete("My-Header")
12
+
13
+ @headers["My-Header"].should be_nil
14
+ @headers.size.should eql(0)
15
+ end
16
+
17
+ it "returns the removed values" do
18
+ @headers["My-Header"] = "test"
19
+ @headers.delete("My-Header").should == ["test"]
20
+ end
21
+
22
+ it "is case-insensitive" do
23
+ @headers["My-Header"] = "test"
24
+ @headers.delete("my-header")
25
+
26
+ @headers["My-Header"].should be_nil
27
+ @headers.size.should eql(0)
28
+ end
29
+ end
@@ -0,0 +1,44 @@
1
+ require 'net/http'
2
+ require File.expand_path('../fixtures/classes', __FILE__)
3
+
4
+ describe "Net::HTTPHeader#each_capitalized_name" do
5
+ before(:each) do
6
+ @headers = NetHTTPHeaderSpecs::Example.new
7
+ @headers["My-Header"] = "test"
8
+ @headers.add_field("My-Other-Header", "a")
9
+ @headers.add_field("My-Other-Header", "b")
10
+ end
11
+
12
+ describe "when passed a block" do
13
+ it "yields each header key to the passed block (keys capitalized)" do
14
+ res = []
15
+ @headers.each_capitalized_name do |key|
16
+ res << key
17
+ end
18
+ res.sort.should == ["My-Header", "My-Other-Header"]
19
+ end
20
+ end
21
+
22
+ describe "when passed no block" do
23
+ ruby_version_is "" ... "1.8.7" do
24
+ it "raises a LocalJumpError" do
25
+ lambda { @headers.each_capitalized_name }.should raise_error(LocalJumpError)
26
+ end
27
+ end
28
+
29
+ ruby_version_is "1.8.7" do
30
+ ruby_bug "http://redmine.ruby-lang.org/issues/show/447", "1.8.7" do
31
+ it "returns an Enumerator" do
32
+ enumerator = @headers.each_capitalized_name
33
+ enumerator.should be_an_instance_of(enumerator_class)
34
+
35
+ res = []
36
+ enumerator.each do |key|
37
+ res << key
38
+ end
39
+ res.sort.should == ["My-Header", "My-Other-Header"]
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,8 @@
1
+ require 'net/http'
2
+ require File.expand_path('../fixtures/classes', __FILE__)
3
+ require File.expand_path('../shared/each_capitalized', __FILE__)
4
+
5
+ describe "Net::HTTPHeader#each_capitalized" do
6
+ it_behaves_like :net_httpheader_each_capitalized, :each_capitalized
7
+ end
8
+
@@ -0,0 +1,7 @@
1
+ require 'net/http'
2
+ require File.expand_path('../fixtures/classes', __FILE__)
3
+ require File.expand_path('../shared/each_header', __FILE__)
4
+
5
+ describe "Net::HTTPHeader#each_header" do
6
+ it_behaves_like :net_httpheader_each_header, :each_header
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'net/http'
2
+ require File.expand_path('../fixtures/classes', __FILE__)
3
+ require File.expand_path('../shared/each_name', __FILE__)
4
+
5
+ describe "Net::HTTPHeader#each_key" do
6
+ it_behaves_like :net_httpheader_each_name, :each_key
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'net/http'
2
+ require File.expand_path('../fixtures/classes', __FILE__)
3
+ require File.expand_path('../shared/each_name', __FILE__)
4
+
5
+ describe "Net::HTTPHeader#each_name" do
6
+ it_behaves_like :net_httpheader_each_name, :each_name
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'net/http'
2
+ require File.expand_path('../fixtures/classes', __FILE__)
3
+ require File.expand_path('../shared/each_header', __FILE__)
4
+
5
+ describe "Net::HTTPHeader#each" do
6
+ it_behaves_like :net_httpheader_each_header, :each
7
+ end
@@ -0,0 +1,45 @@
1
+ require 'net/http'
2
+ require File.expand_path('../fixtures/classes', __FILE__)
3
+
4
+ describe "Net::HTTPHeader#each_value" do
5
+ before(:each) do
6
+ @headers = NetHTTPHeaderSpecs::Example.new
7
+ @headers["My-Header"] = "test"
8
+ @headers.add_field("My-Other-Header", "a")
9
+ @headers.add_field("My-Other-Header", "b")
10
+ end
11
+
12
+ describe "when passed a block" do
13
+ it "yields each header entry's joined values" do
14
+ res = []
15
+ @headers.each_value do |value|
16
+ res << value
17
+ end
18
+ res.sort.should == ["a, b", "test"]
19
+ end
20
+ end
21
+
22
+ describe "when passed no block" do
23
+ ruby_version_is "" ... "1.8.7" do
24
+ it "raises a LocalJumpError" do
25
+ lambda { @headers.each_value }.should raise_error(LocalJumpError)
26
+ end
27
+ end
28
+
29
+ # TODO: This should return an Enumerator and not raise an Error
30
+ ruby_version_is "1.8.7" do
31
+ ruby_bug "http://redmine.ruby-lang.org/issues/show/447", "1.8.7" do
32
+ it "returns an Enumerator" do
33
+ enumerator = @headers.each_value
34
+ enumerator.should be_an_instance_of(enumerator_class)
35
+
36
+ res = []
37
+ enumerator.each do |key|
38
+ res << key
39
+ end
40
+ res.sort.should == ["a, b", "test"]
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,38 @@
1
+ require 'net/http'
2
+ require File.expand_path('../fixtures/classes', __FILE__)
3
+
4
+ describe "Net::HTTPHeader#[] when passed key" do
5
+ before(:each) do
6
+ @headers = NetHTTPHeaderSpecs::Example.new
7
+ end
8
+
9
+ it "returns the value of the header entry with the passed key" do
10
+ @headers["My-Header"] = "test"
11
+ @headers["My-Header"].should == "test"
12
+ @headers["My-Other-Header"] = "another test"
13
+ @headers["My-Other-Header"].should == "another test"
14
+ end
15
+
16
+ it "is case-insensitive" do
17
+ @headers["My-Header"] = "test"
18
+
19
+ @headers['My-Header'].should == "test"
20
+ @headers['my-Header'].should == "test"
21
+ @headers['My-header'].should == "test"
22
+ @headers['my-header'].should == "test"
23
+ @headers['MY-HEADER'].should == "test"
24
+ end
25
+
26
+ it "returns multi-element values joined together" do
27
+ @headers["My-Header"] = "test"
28
+ @headers.add_field("My-Header", "another test")
29
+ @headers.add_field("My-Header", "and one more")
30
+
31
+ @headers["My-Header"].should == "test, another test, and one more"
32
+ end
33
+
34
+ it "returns nil for non-existing entries" do
35
+ @headers["My-Header"].should be_nil
36
+ @headers["My-Other-Header"].should be_nil
37
+ end
38
+ end
@@ -0,0 +1,40 @@
1
+ require 'net/http'
2
+ require File.expand_path('../fixtures/classes', __FILE__)
3
+
4
+ describe "Net::HTTPHeader#[]= when passed key, value" do
5
+ before(:each) do
6
+ @headers = NetHTTPHeaderSpecs::Example.new
7
+ end
8
+
9
+ it "sets the header entry with the passed key to the passed value" do
10
+ @headers["My-Header"] = "test"
11
+ @headers["My-Header"].should == "test"
12
+
13
+ @headers["My-Header"] = "overwritten"
14
+ @headers["My-Header"].should == "overwritten"
15
+
16
+ @headers["My-Other-Header"] = "another test"
17
+ @headers["My-Other-Header"].should == "another test"
18
+ end
19
+
20
+ it "is case-insensitive" do
21
+ @headers['My-Header'] = "test"
22
+ @headers['my-Header'] = "another test"
23
+ @headers['My-header'] = "and one more test"
24
+ @headers['my-header'] = "and another one"
25
+ @headers['MY-HEADER'] = "last one"
26
+
27
+ @headers["My-Header"].should == "last one"
28
+ @headers.size.should eql(1)
29
+ end
30
+
31
+ it "removes the header entry with the passed key when the value is false or nil" do
32
+ @headers['My-Header'] = "test"
33
+ @headers['My-Header'] = nil
34
+ @headers['My-Header'].should be_nil
35
+
36
+ @headers['My-Header'] = "test"
37
+ @headers['My-Header'] = false
38
+ @headers['My-Header'].should be_nil
39
+ end
40
+ end