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.
- checksums.yaml +7 -0
- data/.gitignore +0 -1
- data/.travis.yml +7 -0
- data/README.md +2 -2
- data/Rakefile +0 -1
- data/lib/net/http.rb +1 -0
- data/lib/rubysl/net/http.rb +2 -0
- data/lib/rubysl/net/http/http.rb +2290 -0
- data/lib/rubysl/net/http/https.rb +173 -0
- data/lib/{rubysl-net-http → rubysl/net/http}/version.rb +2 -2
- data/rubysl-net-http.gemspec +18 -18
- data/spec/HTTPBadResponse_spec.rb +7 -0
- data/spec/HTTPError_spec.rb +11 -0
- data/spec/HTTPFatalError_spec.rb +11 -0
- data/spec/HTTPHeaderSyntaxError_spec.rb +7 -0
- data/spec/HTTPRetriableError_spec.rb +11 -0
- data/spec/HTTPServerException_spec.rb +11 -0
- data/spec/http/Proxy_spec.rb +34 -0
- data/spec/http/active_spec.rb +7 -0
- data/spec/http/address_spec.rb +8 -0
- data/spec/http/close_on_empty_response_spec.rb +9 -0
- data/spec/http/copy_spec.rb +26 -0
- data/spec/http/default_port_spec.rb +7 -0
- data/spec/http/delete_spec.rb +26 -0
- data/spec/http/finish_spec.rb +30 -0
- data/spec/http/fixtures/http_server.rb +97 -0
- data/spec/http/get2_spec.rb +7 -0
- data/spec/http/get_print_spec.rb +28 -0
- data/spec/http/get_response_spec.rb +28 -0
- data/spec/http/get_spec.rb +52 -0
- data/spec/http/head2_spec.rb +8 -0
- data/spec/http/head_spec.rb +30 -0
- data/spec/http/http_default_port_spec.rb +7 -0
- data/spec/http/https_default_port_spec.rb +7 -0
- data/spec/http/initialize_spec.rb +45 -0
- data/spec/http/inspect_spec.rb +25 -0
- data/spec/http/is_version_1_1_spec.rb +6 -0
- data/spec/http/is_version_1_2_spec.rb +6 -0
- data/spec/http/lock_spec.rb +26 -0
- data/spec/http/mkcol_spec.rb +26 -0
- data/spec/http/move_spec.rb +30 -0
- data/spec/http/new_spec.rb +96 -0
- data/spec/http/newobj_spec.rb +47 -0
- data/spec/http/open_timeout_spec.rb +23 -0
- data/spec/http/options_spec.rb +30 -0
- data/spec/http/port_spec.rb +8 -0
- data/spec/http/post2_spec.rb +7 -0
- data/spec/http/post_form_spec.rb +20 -0
- data/spec/http/post_spec.rb +43 -0
- data/spec/http/propfind_spec.rb +29 -0
- data/spec/http/proppatch_spec.rb +29 -0
- data/spec/http/proxy_address_spec.rb +30 -0
- data/spec/http/proxy_class_spec.rb +8 -0
- data/spec/http/proxy_pass_spec.rb +38 -0
- data/spec/http/proxy_port_spec.rb +38 -0
- data/spec/http/proxy_user_spec.rb +38 -0
- data/spec/http/put2_spec.rb +7 -0
- data/spec/http/put_spec.rb +29 -0
- data/spec/http/read_timeout_spec.rb +23 -0
- data/spec/http/request_get_spec.rb +7 -0
- data/spec/http/request_head_spec.rb +7 -0
- data/spec/http/request_post_spec.rb +7 -0
- data/spec/http/request_put_spec.rb +7 -0
- data/spec/http/request_spec.rb +114 -0
- data/spec/http/request_types_spec.rb +253 -0
- data/spec/http/send_request_spec.rb +123 -0
- data/spec/http/set_debug_output_spec.rb +34 -0
- data/spec/http/shared/request_get.rb +49 -0
- data/spec/http/shared/request_head.rb +49 -0
- data/spec/http/shared/request_post.rb +49 -0
- data/spec/http/shared/request_put.rb +49 -0
- data/spec/http/shared/started.rb +28 -0
- data/spec/http/shared/version_1_1.rb +19 -0
- data/spec/http/shared/version_1_2.rb +6 -0
- data/spec/http/socket_type_spec.rb +7 -0
- data/spec/http/start_spec.rb +115 -0
- data/spec/http/started_spec.rb +7 -0
- data/spec/http/trace_spec.rb +29 -0
- data/spec/http/unlock_spec.rb +29 -0
- data/spec/http/use_ssl_spec.rb +8 -0
- data/spec/http/version_1_1_spec.rb +21 -0
- data/spec/http/version_1_2_spec.rb +19 -0
- data/spec/httpexceptions/fixtures/classes.rb +5 -0
- data/spec/httpexceptions/initialize_spec.rb +16 -0
- data/spec/httpexceptions/response_spec.rb +9 -0
- data/spec/httpgenericrequest/body_exist_spec.rb +26 -0
- data/spec/httpgenericrequest/body_spec.rb +29 -0
- data/spec/httpgenericrequest/body_stream_spec.rb +31 -0
- data/spec/httpgenericrequest/exec_spec.rb +135 -0
- data/spec/httpgenericrequest/inspect_spec.rb +24 -0
- data/spec/httpgenericrequest/method_spec.rb +14 -0
- data/spec/httpgenericrequest/path_spec.rb +11 -0
- data/spec/httpgenericrequest/request_body_permitted_spec.rb +11 -0
- data/spec/httpgenericrequest/response_body_permitted_spec.rb +11 -0
- data/spec/httpgenericrequest/set_body_internal_spec.rb +20 -0
- data/spec/httpheader/add_field_spec.rb +30 -0
- data/spec/httpheader/basic_auth_spec.rb +13 -0
- data/spec/httpheader/canonical_each_spec.rb +7 -0
- data/spec/httpheader/chunked_spec.rb +21 -0
- data/spec/httpheader/content_length_spec.rb +53 -0
- data/spec/httpheader/content_range_spec.rb +33 -0
- data/spec/httpheader/content_type_spec.rb +25 -0
- data/spec/httpheader/delete_spec.rb +29 -0
- data/spec/httpheader/each_capitalized_name_spec.rb +44 -0
- data/spec/httpheader/each_capitalized_spec.rb +8 -0
- data/spec/httpheader/each_header_spec.rb +7 -0
- data/spec/httpheader/each_key_spec.rb +7 -0
- data/spec/httpheader/each_name_spec.rb +7 -0
- data/spec/httpheader/each_spec.rb +7 -0
- data/spec/httpheader/each_value_spec.rb +45 -0
- data/spec/httpheader/element_reference_spec.rb +38 -0
- data/spec/httpheader/element_set_spec.rb +40 -0
- data/spec/httpheader/fetch_spec.rb +68 -0
- data/spec/httpheader/fixtures/classes.rb +11 -0
- data/spec/httpheader/form_data_spec.rb +7 -0
- data/spec/httpheader/get_fields_spec.rb +38 -0
- data/spec/httpheader/initialize_http_header_spec.rb +28 -0
- data/spec/httpheader/key_spec.rb +20 -0
- data/spec/httpheader/length_spec.rb +7 -0
- data/spec/httpheader/main_type_spec.rb +23 -0
- data/spec/httpheader/proxy_basic_auth_spec.rb +13 -0
- data/spec/httpheader/range_length_spec.rb +31 -0
- data/spec/httpheader/range_spec.rb +47 -0
- data/spec/httpheader/set_content_type_spec.rb +7 -0
- data/spec/httpheader/set_form_data_spec.rb +7 -0
- data/spec/httpheader/set_range_spec.rb +7 -0
- data/spec/httpheader/shared/each_capitalized.rb +42 -0
- data/spec/httpheader/shared/each_header.rb +42 -0
- data/spec/httpheader/shared/each_name.rb +39 -0
- data/spec/httpheader/shared/set_content_type.rb +20 -0
- data/spec/httpheader/shared/set_form_data.rb +27 -0
- data/spec/httpheader/shared/set_range.rb +89 -0
- data/spec/httpheader/shared/size.rb +18 -0
- data/spec/httpheader/size_spec.rb +7 -0
- data/spec/httpheader/sub_type_spec.rb +31 -0
- data/spec/httpheader/to_hash_spec.rb +24 -0
- data/spec/httpheader/type_params_spec.rb +23 -0
- data/spec/httprequest/initialize_spec.rb +44 -0
- data/spec/httpresponse/body_permitted_spec.rb +12 -0
- data/spec/httpresponse/body_spec.rb +6 -0
- data/spec/httpresponse/code_spec.rb +23 -0
- data/spec/httpresponse/code_type_spec.rb +23 -0
- data/spec/httpresponse/entity_spec.rb +6 -0
- data/spec/httpresponse/error_spec.rb +23 -0
- data/spec/httpresponse/error_type_spec.rb +23 -0
- data/spec/httpresponse/exception_type_spec.rb +12 -0
- data/spec/httpresponse/header_spec.rb +8 -0
- data/spec/httpresponse/http_version_spec.rb +11 -0
- data/spec/httpresponse/initialize_spec.rb +10 -0
- data/spec/httpresponse/inspect_spec.rb +14 -0
- data/spec/httpresponse/message_spec.rb +8 -0
- data/spec/httpresponse/msg_spec.rb +8 -0
- data/spec/httpresponse/read_body_spec.rb +85 -0
- data/spec/httpresponse/read_header_spec.rb +8 -0
- data/spec/httpresponse/read_new_spec.rb +21 -0
- data/spec/httpresponse/reading_body_spec.rb +57 -0
- data/spec/httpresponse/response_spec.rb +8 -0
- data/spec/httpresponse/shared/body.rb +18 -0
- data/spec/httpresponse/to_ary_spec.rb +25 -0
- data/spec/httpresponse/value_spec.rb +23 -0
- metadata +366 -88
- data/lib/rubysl-net-http.rb +0 -9
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require File.expand_path('../fixtures/http_server', __FILE__)
|
3
|
+
|
4
|
+
describe "Net::HTTP#send_request" do
|
5
|
+
before(:all) do
|
6
|
+
NetHTTPSpecs.start_server
|
7
|
+
end
|
8
|
+
|
9
|
+
after(:all) do
|
10
|
+
NetHTTPSpecs.stop_server
|
11
|
+
end
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
@http = Net::HTTP.start("localhost", 3333)
|
15
|
+
end
|
16
|
+
|
17
|
+
after(:each) do
|
18
|
+
@http.finish if @http.started?
|
19
|
+
end
|
20
|
+
|
21
|
+
# TODO: Does only work with GET and POST requests
|
22
|
+
describe "when passed type, path" do
|
23
|
+
it "sends a HTTP Request of the passed type to the passed path" do
|
24
|
+
response = @http.send_request("GET", "/request")
|
25
|
+
response.body.should == "Request type: GET"
|
26
|
+
|
27
|
+
# response = @http.send_request("HEAD", "/request")
|
28
|
+
# response.body.should be_nil
|
29
|
+
|
30
|
+
response = @http.send_request("POST", "/request")
|
31
|
+
response.body.should == "Request type: POST"
|
32
|
+
|
33
|
+
# response = @http.send_request("PUT", "/request")
|
34
|
+
# response.body.should == "Request type: PUT"
|
35
|
+
|
36
|
+
# response = @http.send_request("DELETE", "/request")
|
37
|
+
# response.body.should == "Request type: DELETE"
|
38
|
+
|
39
|
+
# response = @http.send_request("PROPGET", "/request")
|
40
|
+
# response.body.should == "Request type: DELETE"
|
41
|
+
|
42
|
+
# response = @http.send_request("PROPSET", "/request")
|
43
|
+
# response.body.should == "Request type: DELETE"
|
44
|
+
|
45
|
+
# response = @http.send_request("OPTIONS", "/request")
|
46
|
+
# response.body.should be_nil
|
47
|
+
|
48
|
+
# response = @http.send_request("LOCK", "/request")
|
49
|
+
# response.body.should == "Request type: LOCK
|
50
|
+
|
51
|
+
# response = @http.send_request("UNLOCK", "/request")
|
52
|
+
# response.body.should == "Request type: UNLOCK
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "when passed type, path, body" do
|
57
|
+
it "sends a HTTP Request with the passed body" do
|
58
|
+
response = @http.send_request("GET", "/request/body", "test=test")
|
59
|
+
response.body.should == "test=test"
|
60
|
+
|
61
|
+
# response = @http.send_request("HEAD", "/request/body", "test=test")
|
62
|
+
# response.body.should be_nil
|
63
|
+
|
64
|
+
response = @http.send_request("POST", "/request/body", "test=test")
|
65
|
+
response.body.should == "test=test"
|
66
|
+
|
67
|
+
# response = @http.send_request("PUT", "/request/body", "test=test")
|
68
|
+
# response.body.should == "test=test"
|
69
|
+
|
70
|
+
# response = @http.send_request("DELETE", "/request/body", "test=test")
|
71
|
+
# response.body.should == "test=test"
|
72
|
+
|
73
|
+
# response = @http.send_request("PROPGET", "/request/body", "test=test")
|
74
|
+
# response.body.should == "test=test"
|
75
|
+
|
76
|
+
# response = @http.send_request("PROPSET", "/request/body", "test=test")
|
77
|
+
# response.body.should == "test=test"
|
78
|
+
|
79
|
+
# response = @http.send_request("OPTIONS", "/request/body", "test=test")
|
80
|
+
# response.body.should be_nil
|
81
|
+
|
82
|
+
# response = @http.send_request("LOCK", "/request/body", "test=test")
|
83
|
+
# response.body.should == "test=test"
|
84
|
+
|
85
|
+
# response = @http.send_request("UNLOCK", "/request/body", "test=test")
|
86
|
+
# response.body.should == "test=test"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "when passed type, path, body, headers" do
|
91
|
+
it "sends a HTTP Request with the passed headers" do
|
92
|
+
response = @http.send_request("GET", "/request/header", "test=test", "referer" => "http://www.rubyspec.org")
|
93
|
+
response.body.should include('"referer"=>["http://www.rubyspec.org"]')
|
94
|
+
|
95
|
+
# response = @http.send_request("HEAD", "/request/header", "test=test", "referer" => "http://www.rubyspec.org")
|
96
|
+
# response.body.should be_nil
|
97
|
+
|
98
|
+
response = @http.send_request("POST", "/request/header", "test=test", "referer" => "http://www.rubyspec.org")
|
99
|
+
response.body.should include('"referer"=>["http://www.rubyspec.org"]')
|
100
|
+
|
101
|
+
# response = @http.send_request("PUT", "/request/header", "test=test", "referer" => "http://www.rubyspec.org")
|
102
|
+
# response.body.should include('"referer"=>["http://www.rubyspec.org"]')
|
103
|
+
|
104
|
+
# response = @http.send_request("DELETE", "/request/header", "test=test", "referer" => "http://www.rubyspec.org")
|
105
|
+
# response.body.should include('"referer"=>["http://www.rubyspec.org"]')
|
106
|
+
|
107
|
+
# response = @http.send_request("PROPGET", "/request/header", "test=test", "referer" => "http://www.rubyspec.org")
|
108
|
+
# response.body.should include('"referer"=>["http://www.rubyspec.org"]')
|
109
|
+
|
110
|
+
# response = @http.send_request("PROPSET", "/request/header", "test=test", "referer" => "http://www.rubyspec.org")
|
111
|
+
# response.body.should include('"referer"=>["http://www.rubyspec.org"]')
|
112
|
+
|
113
|
+
# response = @http.send_request("OPTIONS", "/request/body", "test=test", "referer" => "http://www.rubyspec.org")
|
114
|
+
# response.body.should be_nil
|
115
|
+
|
116
|
+
# response = @http.send_request("LOCK", "/request/header", "test=test", "referer" => "http://www.rubyspec.org")
|
117
|
+
# response.body.should include('"referer"=>["http://www.rubyspec.org"]')
|
118
|
+
|
119
|
+
# response = @http.send_request("UNLOCK", "/request/header", "test=test", "referer" => "http://www.rubyspec.org")
|
120
|
+
# response.body.should include('"referer"=>["http://www.rubyspec.org"]')
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require "stringio"
|
3
|
+
require File.expand_path('../fixtures/http_server', __FILE__)
|
4
|
+
|
5
|
+
describe "Net::HTTP#set_debug_output when passed io" do
|
6
|
+
before(:all) do
|
7
|
+
NetHTTPSpecs.start_server
|
8
|
+
end
|
9
|
+
|
10
|
+
after(:all) do
|
11
|
+
NetHTTPSpecs.stop_server
|
12
|
+
end
|
13
|
+
|
14
|
+
before(:each) do
|
15
|
+
@http = Net::HTTP.new("localhost", 3333)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "sets the passed io as output stream for debugging" do
|
19
|
+
io = StringIO.new
|
20
|
+
|
21
|
+
@http.set_debug_output(io)
|
22
|
+
@http.start
|
23
|
+
io.string.should_not be_empty
|
24
|
+
size = io.string.size
|
25
|
+
|
26
|
+
@http.get("/")
|
27
|
+
io.string.size.should > size
|
28
|
+
end
|
29
|
+
|
30
|
+
it "outputs a warning when the connection has already been started" do
|
31
|
+
@http.start
|
32
|
+
lambda { @http.set_debug_output(StringIO.new) }.should complain("Net::HTTP#set_debug_output called after HTTP started\n")
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
describe :net_ftp_request_get, :shared => true do
|
2
|
+
before(:all) do
|
3
|
+
NetHTTPSpecs.start_server
|
4
|
+
end
|
5
|
+
|
6
|
+
after(:all) do
|
7
|
+
NetHTTPSpecs.stop_server
|
8
|
+
end
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
@http = Net::HTTP.start("localhost", 3333)
|
12
|
+
end
|
13
|
+
|
14
|
+
after(:each) do
|
15
|
+
@http.finish if @http.started?
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "when passed no block" do
|
19
|
+
it "sends a GET request to the passed path and returns the response" do
|
20
|
+
response = @http.send(@method, "/request")
|
21
|
+
response.body.should == "Request type: GET"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns a Net::HTTPResponse object" do
|
25
|
+
response = @http.send(@method, "/request")
|
26
|
+
response.should be_kind_of(Net::HTTPResponse)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "when passed a block" do
|
31
|
+
it "sends a GET request to the passed path and returns the response" do
|
32
|
+
response = @http.send(@method, "/request") {}
|
33
|
+
response.body.should == "Request type: GET"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "yields the response to the passed block" do
|
37
|
+
yielded = false
|
38
|
+
@http.send(@method, "/request") do |response|
|
39
|
+
response.body.should == "Request type: GET"
|
40
|
+
end
|
41
|
+
yielded = true
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns a Net::HTTPResponse object" do
|
45
|
+
response = @http.send(@method, "/request") {}
|
46
|
+
response.should be_kind_of(Net::HTTPResponse)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
describe :net_ftp_request_head, :shared => true do
|
2
|
+
before(:all) do
|
3
|
+
NetHTTPSpecs.start_server
|
4
|
+
end
|
5
|
+
|
6
|
+
after(:all) do
|
7
|
+
NetHTTPSpecs.stop_server
|
8
|
+
end
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
@http = Net::HTTP.start("localhost", 3333)
|
12
|
+
end
|
13
|
+
|
14
|
+
after(:each) do
|
15
|
+
@http.finish if @http.started?
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "when passed no block" do
|
19
|
+
it "sends a head request to the passed path and returns the response" do
|
20
|
+
response = @http.send(@method, "/request")
|
21
|
+
response.body.should be_nil
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns a Net::HTTPResponse object" do
|
25
|
+
response = @http.send(@method, "/request")
|
26
|
+
response.should be_kind_of(Net::HTTPResponse)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "when passed a block" do
|
31
|
+
it "sends a head request to the passed path and returns the response" do
|
32
|
+
response = @http.send(@method, "/request") {}
|
33
|
+
response.body.should be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
it "yields the response to the passed block" do
|
37
|
+
yielded = false
|
38
|
+
@http.send(@method, "/request") do |response|
|
39
|
+
response.body.should be_nil
|
40
|
+
end
|
41
|
+
yielded = true
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns a Net::HTTPResponse object" do
|
45
|
+
response = @http.send(@method, "/request") {}
|
46
|
+
response.should be_kind_of(Net::HTTPResponse)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
describe :net_ftp_request_post, :shared => true do
|
2
|
+
before(:all) do
|
3
|
+
NetHTTPSpecs.start_server
|
4
|
+
end
|
5
|
+
|
6
|
+
after(:all) do
|
7
|
+
NetHTTPSpecs.stop_server
|
8
|
+
end
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
@http = Net::HTTP.start("localhost", 3333)
|
12
|
+
end
|
13
|
+
|
14
|
+
after(:each) do
|
15
|
+
@http.finish if @http.started?
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "when passed no block" do
|
19
|
+
it "sends a post request to the passed path and returns the response" do
|
20
|
+
response = @http.send(@method, "/request", "test=test")
|
21
|
+
response.body.should == "Request type: POST"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns a Net::HTTPResponse object" do
|
25
|
+
response = @http.send(@method, "/request", "test=test")
|
26
|
+
response.should be_kind_of(Net::HTTPResponse)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "when passed a block" do
|
31
|
+
it "sends a post request to the passed path and returns the response" do
|
32
|
+
response = @http.send(@method, "/request", "test=test") {}
|
33
|
+
response.body.should == "Request type: POST"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "yields the response to the passed block" do
|
37
|
+
yielded = false
|
38
|
+
@http.send(@method, "/request", "test=test") do |response|
|
39
|
+
response.body.should == "Request type: POST"
|
40
|
+
end
|
41
|
+
yielded = true
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns a Net::HTTPResponse object" do
|
45
|
+
response = @http.send(@method, "/request", "test=test") {}
|
46
|
+
response.should be_kind_of(Net::HTTPResponse)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
describe :net_ftp_request_put, :shared => true do
|
2
|
+
before(:all) do
|
3
|
+
NetHTTPSpecs.start_server
|
4
|
+
end
|
5
|
+
|
6
|
+
after(:all) do
|
7
|
+
NetHTTPSpecs.stop_server
|
8
|
+
end
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
@http = Net::HTTP.start("localhost", 3333)
|
12
|
+
end
|
13
|
+
|
14
|
+
after(:each) do
|
15
|
+
@http.finish if @http.started?
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "when passed no block" do
|
19
|
+
it "sends a put request to the passed path and returns the response" do
|
20
|
+
response = @http.send(@method, "/request", "test=test")
|
21
|
+
response.body.should == "Request type: PUT"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns a Net::HTTPResponse object" do
|
25
|
+
response = @http.send(@method, "/request", "test=test")
|
26
|
+
response.should be_kind_of(Net::HTTPResponse)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "when passed a block" do
|
31
|
+
it "sends a put request to the passed path and returns the response" do
|
32
|
+
response = @http.send(@method, "/request", "test=test") {}
|
33
|
+
response.body.should == "Request type: PUT"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "yields the response to the passed block" do
|
37
|
+
yielded = false
|
38
|
+
@http.send(@method, "/request", "test=test") do |response|
|
39
|
+
response.body.should == "Request type: PUT"
|
40
|
+
end
|
41
|
+
yielded = true
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns a Net::HTTPResponse object" do
|
45
|
+
response = @http.send(@method, "/request", "test=test") {}
|
46
|
+
response.should be_kind_of(Net::HTTPResponse)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
describe :net_http_started_p, :shared => true do
|
2
|
+
before(:all) do
|
3
|
+
NetHTTPSpecs.start_server
|
4
|
+
end
|
5
|
+
|
6
|
+
after(:all) do
|
7
|
+
NetHTTPSpecs.stop_server
|
8
|
+
end
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
@net = Net::HTTP.new("localhost", 3333)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns true when self has been started" do
|
15
|
+
@net.start
|
16
|
+
@net.send(@method).should be_true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns false when self has not been started yet" do
|
20
|
+
@net.send(@method).should be_false
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns false when self has been stopped again" do
|
24
|
+
@net.start
|
25
|
+
@net.finish
|
26
|
+
@net.send(@method).should be_false
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
ruby_version_is ''...'1.9.3' do
|
2
|
+
describe :net_http_version_1_1_p, :shared => true do
|
3
|
+
it "returns the state of net/http 1.1 features" do
|
4
|
+
Net::HTTP.version_1_2
|
5
|
+
Net::HTTP.send(@method).should be_false
|
6
|
+
Net::HTTP.version_1_1
|
7
|
+
Net::HTTP.send(@method).should be_true
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
ruby_version_is '1.9.3' do
|
13
|
+
describe :net_http_version_1_1_p, :shared => true do
|
14
|
+
it "returns the state of net/http 1.1 features" do
|
15
|
+
Net::HTTP.version_1_2
|
16
|
+
Net::HTTP.send(@method).should be_false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require File.expand_path('../fixtures/http_server', __FILE__)
|
3
|
+
|
4
|
+
describe "Net::HTTP.start" do
|
5
|
+
before(:all) do
|
6
|
+
NetHTTPSpecs.start_server
|
7
|
+
end
|
8
|
+
|
9
|
+
after(:all) do
|
10
|
+
NetHTTPSpecs.stop_server
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "when not passed a block" do
|
14
|
+
before(:each) do
|
15
|
+
@http = Net::HTTP.start("localhost", 3333)
|
16
|
+
end
|
17
|
+
|
18
|
+
after(:each) do
|
19
|
+
@http.finish if @http.started?
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns a new Net::HTTP object for the passed address and port" do
|
23
|
+
@http.should be_kind_of(Net::HTTP)
|
24
|
+
@http.address.should == "localhost"
|
25
|
+
@http.port.should == 3333
|
26
|
+
end
|
27
|
+
|
28
|
+
it "opens the tcp connection" do
|
29
|
+
@http.started?.should be_true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "when passed a block" do
|
34
|
+
it "returns the blocks return value" do
|
35
|
+
Net::HTTP.start("localhost", 3333) { :test }.should == :test
|
36
|
+
end
|
37
|
+
|
38
|
+
it "yields the new Net::HTTP object to the block" do
|
39
|
+
yielded = false
|
40
|
+
Net::HTTP.start("localhost", 3333) do |net|
|
41
|
+
yielded = true
|
42
|
+
net.should be_kind_of(Net::HTTP)
|
43
|
+
end
|
44
|
+
yielded.should be_true
|
45
|
+
end
|
46
|
+
|
47
|
+
it "opens the tcp connection before yielding" do
|
48
|
+
Net::HTTP.start("localhost", 3333) { |http| http.started?.should be_true }
|
49
|
+
end
|
50
|
+
|
51
|
+
it "closes the tcp connection after yielding" do
|
52
|
+
net = nil
|
53
|
+
Net::HTTP.start("localhost", 3333) { |x| net = x }
|
54
|
+
net.started?.should be_false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "Net::HTTP#start" do
|
60
|
+
before(:all) do
|
61
|
+
NetHTTPSpecs.start_server
|
62
|
+
end
|
63
|
+
|
64
|
+
after(:all) do
|
65
|
+
NetHTTPSpecs.stop_server
|
66
|
+
end
|
67
|
+
|
68
|
+
before(:each) do
|
69
|
+
@http = Net::HTTP.new("localhost", 3333)
|
70
|
+
end
|
71
|
+
|
72
|
+
after(:each) do
|
73
|
+
@http.finish if @http.started?
|
74
|
+
end
|
75
|
+
|
76
|
+
it "returns self" do
|
77
|
+
@http.start.should equal(@http)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "opens the tcp connection" do
|
81
|
+
@http.start
|
82
|
+
@http.started?.should be_true
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "when self has already been started" do
|
86
|
+
it "raises an IOError" do
|
87
|
+
@http.start
|
88
|
+
lambda { @http.start }.should raise_error(IOError)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "when passed a block" do
|
93
|
+
it "returns the blocks return value" do
|
94
|
+
@http.start { :test }.should == :test
|
95
|
+
end
|
96
|
+
|
97
|
+
it "yields the new Net::HTTP object to the block" do
|
98
|
+
yielded = false
|
99
|
+
@http.start do |http|
|
100
|
+
yielded = true
|
101
|
+
http.should equal(@http)
|
102
|
+
end
|
103
|
+
yielded.should be_true
|
104
|
+
end
|
105
|
+
|
106
|
+
it "opens the tcp connection before yielding" do
|
107
|
+
@http.start { |http| http.started?.should be_true }
|
108
|
+
end
|
109
|
+
|
110
|
+
it "closes the tcp connection after yielding" do
|
111
|
+
@http.start { }
|
112
|
+
@http.started?.should be_false
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|