summaryrefslogtreecommitdiff
path: root/spec/rubyspec/library/net/http/http/send_request_spec.rb
blob: 8d21b6aa3b9fe4e47256e895cb9144d0ffa5b4d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)

describe "Net::HTTP#send_request" do
  before :each do
    NetHTTPSpecs.start_server
    @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
  end

  after :each do
    @http.finish if @http.started?
    NetHTTPSpecs.stop_server
  end

  # TODO: Does only work with GET and POST requests
  describe "when passed type, path" do
    it "sends a HTTP Request of the passed type to the passed path" do
      response = @http.send_request("GET", "/request")
      response.body.should == "Request type: GET"

      # response = @http.send_request("HEAD", "/request")
      # response.body.should be_nil

      response = @http.send_request("POST", "/request")
      response.body.should == "Request type: POST"

      # response = @http.send_request("PUT", "/request")
      # response.body.should == "Request type: PUT"

      # response = @http.send_request("DELETE", "/request")
      # response.body.should == "Request type: DELETE"

      # response = @http.send_request("PROPGET", "/request")
      # response.body.should == "Request type: DELETE"

      # response = @http.send_request("PROPSET", "/request")
      # response.body.should == "Request type: DELETE"

      # response = @http.send_request("OPTIONS", "/request")
      # response.body.should be_nil

      # response = @http.send_request("LOCK", "/request")
      # response.body.should == "Request type: LOCK

      # response = @http.send_request("UNLOCK", "/request")
      # response.body.should == "Request type: UNLOCK
    end
  end

  describe "when passed type, path, body" do
    it "sends a HTTP Request with the passed body" do
      response = @http.send_request("GET", "/request/body", "test=test")
      response.body.should == "test=test"

      # response = @http.send_request("HEAD", "/request/body", "test=test")
      # response.body.should be_nil

      response = @http.send_request("POST", "/request/body", "test=test")
      response.body.should == "test=test"

      # response = @http.send_request("PUT", "/request/body", "test=test")
      # response.body.should == "test=test"

      # response = @http.send_request("DELETE", "/request/body", "test=test")
      # response.body.should == "test=test"

      # response = @http.send_request("PROPGET", "/request/body", "test=test")
      # response.body.should == "test=test"

      # response = @http.send_request("PROPSET", "/request/body", "test=test")
      # response.body.should == "test=test"

      # response = @http.send_request("OPTIONS", "/request/body", "test=test")
      # response.body.should be_nil

      # response = @http.send_request("LOCK", "/request/body", "test=test")
      # response.body.should == "test=test"

      # response = @http.send_request("UNLOCK", "/request/body", "test=test")
      # response.body.should == "test=test"
    end
  end

  describe "when passed type, path, body, headers" do
    it "sends a HTTP Request with the passed headers" do
      response = @http.send_request("GET", "/request/header", "test=test", "referer" => "http://www.rubyspec.org")
      response.body.should include('"referer"=>["http://www.rubyspec.org"]')

      # response = @http.send_request("HEAD", "/request/header", "test=test", "referer" => "http://www.rubyspec.org")
      # response.body.should be_nil

      response = @http.send_request("POST", "/request/header", "test=test", "referer" => "http://www.rubyspec.org")
      response.body.should include('"referer"=>["http://www.rubyspec.org"]')

      # response = @http.send_request("PUT", "/request/header", "test=test", "referer" => "http://www.rubyspec.org")
      # response.body.should include('"referer"=>["http://www.rubyspec.org"]')

      # response = @http.send_request("DELETE", "/request/header", "test=test", "referer" => "http://www.rubyspec.org")
      # response.body.should include('"referer"=>["http://www.rubyspec.org"]')

      # response = @http.send_request("PROPGET", "/request/header", "test=test", "referer" => "http://www.rubyspec.org")
      # response.body.should include('"referer"=>["http://www.rubyspec.org"]')

      # response = @http.send_request("PROPSET", "/request/header", "test=test", "referer" => "http://www.rubyspec.org")
      # response.body.should include('"referer"=>["http://www.rubyspec.org"]')

      # response = @http.send_request("OPTIONS", "/request/body", "test=test", "referer" => "http://www.rubyspec.org")
      # response.body.should be_nil

      # response = @http.send_request("LOCK", "/request/header", "test=test", "referer" => "http://www.rubyspec.org")
      # response.body.should include('"referer"=>["http://www.rubyspec.org"]')

      # response = @http.send_request("UNLOCK", "/request/header", "test=test", "referer" => "http://www.rubyspec.org")
      # response.body.should include('"referer"=>["http://www.rubyspec.org"]')
    end
  end
end