httpi 2.1.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,51 +5,51 @@ describe HTTPI::Auth::SSL do
5
5
 
6
6
  describe "VERIFY_MODES" do
7
7
  it "contains the supported SSL verify modes" do
8
- HTTPI::Auth::SSL::VERIFY_MODES.should == [:none, :peer, :fail_if_no_peer_cert, :client_once]
8
+ expect(HTTPI::Auth::SSL::VERIFY_MODES).to eq([:none, :peer, :fail_if_no_peer_cert, :client_once])
9
9
  end
10
10
  end
11
11
 
12
12
  describe "#present?" do
13
13
  it "defaults to return false" do
14
14
  ssl = HTTPI::Auth::SSL.new
15
- ssl.should_not be_present
15
+ expect(ssl).not_to be_present
16
16
  end
17
17
 
18
18
  it "returns false if only a client key was specified" do
19
19
  ssl = HTTPI::Auth::SSL.new
20
20
  ssl.cert_key_file = "spec/fixtures/client_key.pem"
21
21
 
22
- ssl.should_not be_present
22
+ expect(ssl).not_to be_present
23
23
  end
24
24
 
25
25
  it "returns false if only a client key was specified" do
26
26
  ssl = HTTPI::Auth::SSL.new
27
27
  ssl.cert_file = "spec/fixtures/client_cert.pem"
28
28
 
29
- ssl.should_not be_present
29
+ expect(ssl).not_to be_present
30
30
  end
31
31
 
32
32
  it "returns true if both client key and cert are present" do
33
- ssl.should be_present
33
+ expect(ssl).to be_present
34
34
  end
35
35
 
36
36
  it "returns true of the verify_mode is :none" do
37
37
  ssl = HTTPI::Auth::SSL.new
38
38
  ssl.verify_mode = :none
39
- ssl.should be_present
39
+ expect(ssl).to be_present
40
40
  end
41
41
  end
42
42
 
43
43
  describe "#verify_mode" do
44
44
  it "defaults to return :peer" do
45
- ssl.verify_mode.should == :peer
45
+ expect(ssl.verify_mode).to eq(:peer)
46
46
  end
47
47
 
48
48
  it "sets the verify mode to use" do
49
49
  ssl = HTTPI::Auth::SSL.new
50
50
 
51
51
  ssl.verify_mode = :none
52
- ssl.verify_mode.should == :none
52
+ expect(ssl.verify_mode).to eq(:none)
53
53
  end
54
54
 
55
55
  it "raises an ArgumentError if the given mode is not supported" do
@@ -61,37 +61,37 @@ describe HTTPI::Auth::SSL do
61
61
 
62
62
  describe "#cert" do
63
63
  it "returns an OpenSSL::X509::Certificate for the given cert_file" do
64
- ssl.cert.should be_a(OpenSSL::X509::Certificate)
64
+ expect(ssl.cert).to be_a(OpenSSL::X509::Certificate)
65
65
  end
66
66
 
67
67
  it "returns nil if no cert_file was given" do
68
68
  ssl = HTTPI::Auth::SSL.new
69
- ssl.cert.should be_nil
69
+ expect(ssl.cert).to be_nil
70
70
  end
71
71
 
72
72
  it "returns the explicitly given certificate if set" do
73
73
  ssl = HTTPI::Auth::SSL.new
74
74
  cert = OpenSSL::X509::Certificate.new
75
75
  ssl.cert = cert
76
- ssl.cert.should == cert
76
+ expect(ssl.cert).to eq(cert)
77
77
  end
78
78
  end
79
79
 
80
80
  describe "#cert_key" do
81
81
  it "returns a OpenSSL::PKey::RSA for the given cert_key" do
82
- ssl.cert_key.should be_a(OpenSSL::PKey::RSA)
82
+ expect(ssl.cert_key).to be_a(OpenSSL::PKey::RSA)
83
83
  end
84
84
 
85
85
  it "returns nil if no cert_key_file was given" do
86
86
  ssl = HTTPI::Auth::SSL.new
87
- ssl.cert_key.should be_nil
87
+ expect(ssl.cert_key).to be_nil
88
88
  end
89
89
 
90
90
  it "returns the explicitly given key if set" do
91
91
  ssl = HTTPI::Auth::SSL.new
92
92
  key = OpenSSL::PKey::RSA.new
93
93
  ssl.cert_key = key
94
- ssl.cert_key.should == key
94
+ expect(ssl.cert_key).to eq(key)
95
95
  end
96
96
  end
97
97
 
@@ -100,7 +100,7 @@ describe HTTPI::Auth::SSL do
100
100
  ssl = HTTPI::Auth::SSL.new
101
101
 
102
102
  ssl.ca_cert_file = "spec/fixtures/client_cert.pem"
103
- ssl.ca_cert.should be_a(OpenSSL::X509::Certificate)
103
+ expect(ssl.ca_cert).to be_a(OpenSSL::X509::Certificate)
104
104
  end
105
105
  end
106
106
 
@@ -109,34 +109,34 @@ describe HTTPI::Auth::SSL do
109
109
  ssl = HTTPI::Auth::SSL.new
110
110
 
111
111
  ssl.verify_mode = :none
112
- ssl.openssl_verify_mode.should == OpenSSL::SSL::VERIFY_NONE
112
+ expect(ssl.openssl_verify_mode).to eq(OpenSSL::SSL::VERIFY_NONE)
113
113
  end
114
114
 
115
115
  it "returns the OpenSSL verify mode for :peer" do
116
116
  ssl = HTTPI::Auth::SSL.new
117
117
 
118
118
  ssl.verify_mode = :peer
119
- ssl.openssl_verify_mode.should == OpenSSL::SSL::VERIFY_PEER
119
+ expect(ssl.openssl_verify_mode).to eq(OpenSSL::SSL::VERIFY_PEER)
120
120
  end
121
121
 
122
122
  it "returns the OpenSSL verify mode for :fail_if_no_peer_cert" do
123
123
  ssl = HTTPI::Auth::SSL.new
124
124
 
125
125
  ssl.verify_mode = :fail_if_no_peer_cert
126
- ssl.openssl_verify_mode.should == OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT
126
+ expect(ssl.openssl_verify_mode).to eq(OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT)
127
127
  end
128
128
 
129
129
  it "returns the OpenSSL verify mode for :client_once" do
130
130
  ssl = HTTPI::Auth::SSL.new
131
131
 
132
132
  ssl.verify_mode = :client_once
133
- ssl.openssl_verify_mode.should == OpenSSL::SSL::VERIFY_CLIENT_ONCE
133
+ expect(ssl.openssl_verify_mode).to eq(OpenSSL::SSL::VERIFY_CLIENT_ONCE)
134
134
  end
135
135
  end
136
136
 
137
137
  describe "SSL_VERSIONS" do
138
138
  it "contains the supported SSL versions" do
139
- HTTPI::Auth::SSL::SSL_VERSIONS.should == [:TLSv1, :SSLv2, :SSLv3]
139
+ expect(HTTPI::Auth::SSL::SSL_VERSIONS).to eq([:TLSv1, :SSLv2, :SSLv3])
140
140
  end
141
141
  end
142
142
 
@@ -145,17 +145,17 @@ describe HTTPI::Auth::SSL do
145
145
 
146
146
  it 'returns the SSL version for :TLSv1' do
147
147
  subject.ssl_version = :TLSv1
148
- subject.ssl_version.should eq(:TLSv1)
148
+ expect(subject.ssl_version).to eq(:TLSv1)
149
149
  end
150
150
 
151
151
  it 'returns the SSL version for :SSLv2' do
152
152
  subject.ssl_version = :SSLv2
153
- subject.ssl_version.should eq(:SSLv2)
153
+ expect(subject.ssl_version).to eq(:SSLv2)
154
154
  end
155
155
 
156
156
  it 'returns the SSL version for :SSLv3' do
157
157
  subject.ssl_version = :SSLv3
158
- subject.ssl_version.should eq(:SSLv3)
158
+ expect(subject.ssl_version).to eq(:SSLv3)
159
159
  end
160
160
 
161
161
  it 'raises ArgumentError if the version is unsupported' do
@@ -10,26 +10,26 @@ describe HTTPI::Cookie do
10
10
  headers = { "Set-Cookie" => "token=strawberry; Path=/; HttpOnly" }
11
11
  cookies = HTTPI::Cookie.list_from_headers(headers)
12
12
 
13
- cookies.should have(1).item
14
- cookies.first.should be_a(HTTPI::Cookie)
13
+ expect(cookies.size).to eq(1)
14
+ expect(cookies.first).to be_a(HTTPI::Cookie)
15
15
  end
16
16
 
17
17
  it "handles multiple cookies" do
18
18
  headers = { "Set-Cookie" => ["user=chucknorris; Path=/; HttpOnly", "token=strawberry; Path=/; HttpOnly"] }
19
19
  cookies = HTTPI::Cookie.list_from_headers(headers)
20
- cookies.should have(2).items
20
+ expect(cookies.size).to eq(2)
21
21
  end
22
22
  end
23
23
 
24
24
  describe "#name" do
25
25
  it "returns the name of the cookie" do
26
- cookie.name.should == "token"
26
+ expect(cookie.name).to eq("token")
27
27
  end
28
28
  end
29
29
 
30
30
  describe "#name_and_value" do
31
31
  it "returns the name and value of the cookie" do
32
- cookie.name_and_value.should == "token=choc-choc-chip"
32
+ expect(cookie.name_and_value).to eq("token=choc-choc-chip")
33
33
  end
34
34
  end
35
35
 
@@ -9,14 +9,14 @@ describe HTTPI::CookieStore do
9
9
  it "stores a set of cookies" do
10
10
  cookie_store = HTTPI::CookieStore.new
11
11
  cookie_store.add(user_cookie, token_cookie)
12
- cookie_store.fetch.should include("user=chucknorris", "token=strawberry")
12
+ expect(cookie_store.fetch).to include("user=chucknorris", "token=strawberry")
13
13
 
14
14
  # add a new token cookie with a different value
15
15
  token_cookie = some_cookie(:token, "choc-choc-chip")
16
16
  cookie_store.add(token_cookie)
17
17
 
18
- cookie_store.fetch.should include("token=choc-choc-chip")
19
- cookie_store.fetch.should_not include("token=strawberry")
18
+ expect(cookie_store.fetch).to include("token=choc-choc-chip")
19
+ expect(cookie_store.fetch).not_to include("token=strawberry")
20
20
  end
21
21
 
22
22
  def some_cookie(name, value)
@@ -249,19 +249,19 @@ describe HTTPI do
249
249
 
250
250
  describe ".log" do
251
251
  it "defaults to true" do
252
- HTTPI.log?.should be_true
252
+ expect(HTTPI.log?).to be_true
253
253
  end
254
254
  end
255
255
 
256
256
  describe ".logger" do
257
257
  it "defaults to Logger writing to STDOUT" do
258
- HTTPI.logger.should be_a(Logger)
258
+ expect(HTTPI.logger).to be_a(Logger)
259
259
  end
260
260
  end
261
261
 
262
262
  describe ".log_level" do
263
263
  it "defaults to :debug" do
264
- HTTPI.log_level.should == :debug
264
+ expect(HTTPI.log_level).to eq(:debug)
265
265
  end
266
266
  end
267
267
 
@@ -7,25 +7,25 @@ describe HTTPI::Request do
7
7
  describe ".new" do
8
8
  it "accepts a url" do
9
9
  request = HTTPI::Request.new "http://example.com"
10
- request.url.should == URI("http://example.com")
10
+ expect(request.url).to eq(URI("http://example.com"))
11
11
  end
12
12
 
13
13
  it "accepts a Hash of accessors to set" do
14
14
  request = HTTPI::Request.new :url => "http://example.com", :open_timeout => 30
15
- request.url.should == URI("http://example.com")
16
- request.open_timeout.should == 30
15
+ expect(request.url).to eq(URI("http://example.com"))
16
+ expect(request.open_timeout).to eq(30)
17
17
  end
18
18
  end
19
19
 
20
20
  describe "#url" do
21
21
  it "lets you specify the URL to access as a String" do
22
22
  request.url = "http://example.com"
23
- request.url.should == URI("http://example.com")
23
+ expect(request.url).to eq(URI("http://example.com"))
24
24
  end
25
25
 
26
26
  it "also accepts a URI object" do
27
27
  request.url = URI("http://example.com")
28
- request.url.should == URI("http://example.com")
28
+ expect(request.url).to eq(URI("http://example.com"))
29
29
  end
30
30
 
31
31
  it "raises an ArgumentError in case of an invalid url" do
@@ -34,12 +34,12 @@ describe HTTPI::Request do
34
34
 
35
35
  it "uses username and password as basic authentication if present in the URL" do
36
36
  request.url = "http://username:password@example.com"
37
- request.auth.basic.should == ['username', 'password']
37
+ expect(request.auth.basic).to eq(['username', 'password'])
38
38
  end
39
39
 
40
40
  it "uses a blank password if only username is specified in the URL" do
41
41
  request.url = "http://username@example.com"
42
- request.auth.basic.should == ['username', '']
42
+ expect(request.auth.basic).to eq(['username', ''])
43
43
  end
44
44
  end
45
45
 
@@ -50,37 +50,37 @@ describe HTTPI::Request do
50
50
  it "lets you specify query parameter as String" do
51
51
  request.url = "http://example.com"
52
52
  request.query = "q=query"
53
- request.url.to_s.should == "http://example.com?q=query"
53
+ expect(request.url.to_s).to eq("http://example.com?q=query")
54
54
  end
55
55
  it "lets you specify query parameter as Hash" do
56
56
  request.url = "http://example.com"
57
57
  request.query = {:q => "query"}
58
- request.url.to_s.should == "http://example.com?q=query"
58
+ expect(request.url.to_s).to eq("http://example.com?q=query")
59
59
  end
60
60
  it "getter return nil for invalid url" do
61
- request.query.should be_nil
61
+ expect(request.query).to be_nil
62
62
  end
63
63
  it "getter return String for query parameter as String" do
64
64
  request.url = "http://example.com"
65
65
  request.query = "q=query"
66
- request.query.should == "q=query"
66
+ expect(request.query).to eq("q=query")
67
67
  end
68
68
  it "getter return String for query parameter as Hash" do
69
69
  request.url = "http://example.com"
70
70
  request.query = {:q => "query"}
71
- request.query.should == "q=query"
71
+ expect(request.query).to eq("q=query")
72
72
  end
73
73
  end
74
74
 
75
75
  describe "#proxy" do
76
76
  it "lets you specify the proxy URL to use as a String" do
77
77
  request.proxy = "http://proxy.example.com"
78
- request.proxy.should == URI("http://proxy.example.com")
78
+ expect(request.proxy).to eq(URI("http://proxy.example.com"))
79
79
  end
80
80
 
81
81
  it "also accepts a URI object" do
82
82
  request.proxy = URI("http://proxy.example.com")
83
- request.proxy.should == URI("http://proxy.example.com")
83
+ expect(request.proxy).to eq(URI("http://proxy.example.com"))
84
84
  end
85
85
 
86
86
  it "raises an ArgumentError in case of an invalid url" do
@@ -90,23 +90,23 @@ describe HTTPI::Request do
90
90
 
91
91
  describe "#ssl" do
92
92
  it "returns false if no request url was specified" do
93
- request.should_not be_ssl
93
+ expect(request).not_to be_ssl
94
94
  end
95
95
 
96
96
  it "returns false if the request url does not start with https" do
97
97
  request.url = "http://example.com"
98
- request.should_not be_ssl
98
+ expect(request).not_to be_ssl
99
99
  end
100
100
 
101
101
  it "returns true if the request url starts with https" do
102
102
  request.url = "https://example.com"
103
- request.should be_ssl
103
+ expect(request).to be_ssl
104
104
  end
105
105
 
106
106
  context "with an explicit value" do
107
107
  it "returns the value" do
108
108
  request.ssl = true
109
- request.should be_ssl
109
+ expect(request).to be_ssl
110
110
  end
111
111
  end
112
112
  end
@@ -114,32 +114,32 @@ describe HTTPI::Request do
114
114
  describe "#headers" do
115
115
  it "lets you specify a Hash of HTTP request headers" do
116
116
  request.headers = { "Accept-Encoding" => "gzip" }
117
- request.headers.should == { "Accept-Encoding" => "gzip" }
117
+ expect(request.headers).to eq({ "Accept-Encoding" => "gzip" })
118
118
  end
119
119
 
120
120
  it "defaults to return an empty Hash" do
121
- request.headers.should == {}
121
+ expect(request.headers).to eq({})
122
122
  end
123
123
  end
124
124
 
125
125
  describe "#gzip" do
126
126
  it "adds the proper 'Accept-Encoding' header" do
127
127
  request.gzip
128
- request.headers["Accept-Encoding"].should == "gzip,deflate"
128
+ expect(request.headers["Accept-Encoding"]).to eq("gzip,deflate")
129
129
  end
130
130
  end
131
131
 
132
132
  describe "#set_cookies" do
133
133
  it "sets the cookie header for the next request" do
134
134
  request.set_cookies response_with_cookie("some-cookie=choc-chip")
135
- request.headers["Cookie"].should == "some-cookie=choc-chip"
135
+ expect(request.headers["Cookie"]).to eq("some-cookie=choc-chip")
136
136
  end
137
137
 
138
138
  it "sets additional cookies from subsequent requests" do
139
139
  request.set_cookies response_with_cookie("some-cookie=choc-chip")
140
140
  request.set_cookies response_with_cookie("second-cookie=oatmeal")
141
141
 
142
- request.headers["Cookie"].should include("some-cookie=choc-chip", "second-cookie=oatmeal")
142
+ expect(request.headers["Cookie"]).to include("some-cookie=choc-chip", "second-cookie=oatmeal")
143
143
  end
144
144
 
145
145
  it "accepts an Array of cookies" do
@@ -150,12 +150,12 @@ describe HTTPI::Request do
150
150
 
151
151
  request.set_cookies(cookies)
152
152
 
153
- request.headers["Cookie"].should include("some-cookie=choc-chip", "second-cookie=oatmeal")
153
+ expect(request.headers["Cookie"]).to include("some-cookie=choc-chip", "second-cookie=oatmeal")
154
154
  end
155
155
 
156
156
  it "doesn't do anything if the response contains no cookies" do
157
157
  request.set_cookies HTTPI::Response.new(200, {}, "")
158
- request.headers.should_not include("Cookie")
158
+ expect(request.headers).not_to include("Cookie")
159
159
  end
160
160
 
161
161
  def new_cookie(cookie_string)
@@ -170,47 +170,47 @@ describe HTTPI::Request do
170
170
  describe "#body" do
171
171
  it "lets you specify the HTTP request body using a String" do
172
172
  request.body = "<some>xml</some>"
173
- request.body.should == "<some>xml</some>"
173
+ expect(request.body).to eq("<some>xml</some>")
174
174
  end
175
175
 
176
176
  it "lets you specify the HTTP request body using a Hash" do
177
177
  request.body = {:foo => :bar, :baz => :foo}
178
- request.body.split("&").should =~ ["foo=bar", "baz=foo"]
178
+ expect(request.body.split("&")).to match_array(["foo=bar", "baz=foo"])
179
179
  end
180
180
  end
181
181
 
182
182
  describe "#open_timeout" do
183
183
  it "lets you specify the open timeout" do
184
184
  request.open_timeout = 30
185
- request.open_timeout.should == 30
185
+ expect(request.open_timeout).to eq(30)
186
186
  end
187
187
  end
188
188
 
189
189
  describe "#read_timeout" do
190
190
  it "lets you specify the read timeout" do
191
191
  request.read_timeout = 45
192
- request.read_timeout.should == 45
192
+ expect(request.read_timeout).to eq(45)
193
193
  end
194
194
  end
195
195
 
196
196
  describe "#auth" do
197
197
  it "returns the authentication object" do
198
- request.auth.should be_an(HTTPI::Auth::Config)
198
+ expect(request.auth).to be_an(HTTPI::Auth::Config)
199
199
  end
200
200
 
201
201
  it "memoizes the authentication object" do
202
- request.auth.should equal(request.auth)
202
+ expect(request.auth).to equal(request.auth)
203
203
  end
204
204
  end
205
205
 
206
206
  describe "#auth?" do
207
207
  it "returns true when auth credentials are specified" do
208
208
  request.auth.basic "username", "password"
209
- request.auth?.should be_true
209
+ expect(request.auth?).to be_true
210
210
  end
211
211
 
212
212
  it "returns false otherwise" do
213
- request.auth?.should be_false
213
+ expect(request.auth?).to be_false
214
214
  end
215
215
  end
216
216