httparty 0.13.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of httparty might be problematic. Click here for more details.

Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +92 -0
  4. data/.rubocop_todo.yml +124 -0
  5. data/.simplecov +1 -0
  6. data/.travis.yml +4 -2
  7. data/CONTRIBUTING.md +23 -0
  8. data/Gemfile +8 -3
  9. data/Guardfile +3 -3
  10. data/History +106 -11
  11. data/README.md +19 -20
  12. data/Rakefile +5 -7
  13. data/bin/httparty +18 -14
  14. data/docs/README.md +100 -0
  15. data/examples/README.md +67 -0
  16. data/examples/aaws.rb +5 -5
  17. data/examples/basic.rb +6 -10
  18. data/examples/crack.rb +2 -2
  19. data/examples/custom_parsers.rb +1 -4
  20. data/examples/delicious.rb +8 -8
  21. data/examples/google.rb +2 -2
  22. data/examples/headers_and_user_agents.rb +1 -1
  23. data/examples/logging.rb +36 -0
  24. data/examples/nokogiri_html_parser.rb +0 -3
  25. data/examples/rescue_json.rb +17 -0
  26. data/examples/rubyurl.rb +3 -3
  27. data/examples/stackexchange.rb +24 -0
  28. data/examples/tripit_sign_in.rb +20 -9
  29. data/examples/twitter.rb +7 -7
  30. data/examples/whoismyrep.rb +1 -1
  31. data/features/command_line.feature +90 -2
  32. data/features/digest_authentication.feature +10 -0
  33. data/features/steps/env.rb +16 -11
  34. data/features/steps/httparty_response_steps.rb +18 -14
  35. data/features/steps/httparty_steps.rb +10 -2
  36. data/features/steps/mongrel_helper.rb +35 -2
  37. data/features/steps/remote_service_steps.rb +26 -8
  38. data/features/supports_read_timeout_option.feature +13 -0
  39. data/httparty.gemspec +6 -5
  40. data/lib/httparty/connection_adapter.rb +36 -13
  41. data/lib/httparty/cookie_hash.rb +3 -4
  42. data/lib/httparty/exceptions.rb +4 -1
  43. data/lib/httparty/hash_conversions.rb +17 -15
  44. data/lib/httparty/logger/{apache_logger.rb → apache_formatter.rb} +3 -3
  45. data/lib/httparty/logger/curl_formatter.rb +91 -0
  46. data/lib/httparty/logger/logger.rb +18 -10
  47. data/lib/httparty/module_inheritable_attributes.rb +1 -1
  48. data/lib/httparty/net_digest_auth.rb +69 -18
  49. data/lib/httparty/parser.rb +4 -2
  50. data/lib/httparty/request.rb +105 -48
  51. data/lib/httparty/response.rb +31 -6
  52. data/lib/httparty/version.rb +1 -1
  53. data/lib/httparty.rb +132 -72
  54. data/spec/httparty/connection_adapter_spec.rb +285 -88
  55. data/spec/httparty/cookie_hash_spec.rb +46 -29
  56. data/spec/httparty/exception_spec.rb +29 -7
  57. data/spec/httparty/hash_conversions_spec.rb +49 -0
  58. data/spec/httparty/logger/apache_formatter_spec.rb +41 -0
  59. data/spec/httparty/logger/curl_formatter_spec.rb +119 -0
  60. data/spec/httparty/logger/logger_spec.rb +23 -7
  61. data/spec/httparty/net_digest_auth_spec.rb +118 -30
  62. data/spec/httparty/parser_spec.rb +43 -35
  63. data/spec/httparty/request_spec.rb +734 -182
  64. data/spec/httparty/response_spec.rb +139 -69
  65. data/spec/httparty/ssl_spec.rb +22 -22
  66. data/spec/httparty_spec.rb +307 -199
  67. data/spec/spec_helper.rb +34 -12
  68. data/spec/support/ssl_test_helper.rb +6 -6
  69. data/spec/support/ssl_test_server.rb +21 -21
  70. data/spec/support/stub_response.rb +20 -14
  71. data/website/index.html +3 -3
  72. metadata +30 -33
  73. data/lib/httparty/core_extensions.rb +0 -32
  74. data/lib/httparty/logger/curl_logger.rb +0 -48
  75. data/spec/httparty/logger/apache_logger_spec.rb +0 -26
  76. data/spec/httparty/logger/curl_logger_spec.rb +0 -18
  77. data/spec/spec.opts +0 -2
@@ -1,12 +1,12 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
2
 
3
- describe HTTParty::Response do
3
+ RSpec.describe HTTParty::Response do
4
4
  before do
5
5
  @last_modified = Date.new(2010, 1, 15).to_s
6
6
  @content_length = '1024'
7
7
  @request_object = HTTParty::Request.new Net::HTTP::Get, '/'
8
8
  @response_object = Net::HTTPOK.new('1.1', 200, 'OK')
9
- @response_object.stub(:body => "{foo:'bar'}")
9
+ allow(@response_object).to receive_messages(body: "{foo:'bar'}")
10
10
  @response_object['last-modified'] = @last_modified
11
11
  @response_object['content-length'] = @content_length
12
12
  @parsed_response = lambda { {"foo" => "bar"} }
@@ -15,79 +15,111 @@ describe HTTParty::Response do
15
15
 
16
16
  describe ".underscore" do
17
17
  it "works with one capitalized word" do
18
- HTTParty::Response.underscore("Accepted").should == "accepted"
18
+ expect(HTTParty::Response.underscore("Accepted")).to eq("accepted")
19
19
  end
20
20
 
21
21
  it "works with titlecase" do
22
- HTTParty::Response.underscore("BadGateway").should == "bad_gateway"
22
+ expect(HTTParty::Response.underscore("BadGateway")).to eq("bad_gateway")
23
23
  end
24
24
 
25
25
  it "works with all caps" do
26
- HTTParty::Response.underscore("OK").should == "ok"
26
+ expect(HTTParty::Response.underscore("OK")).to eq("ok")
27
27
  end
28
28
  end
29
29
 
30
30
  describe "initialization" do
31
31
  it "should set the Net::HTTP Response" do
32
- @response.response.should == @response_object
32
+ expect(@response.response).to eq(@response_object)
33
33
  end
34
34
 
35
35
  it "should set body" do
36
- @response.body.should == @response_object.body
36
+ expect(@response.body).to eq(@response_object.body)
37
37
  end
38
38
 
39
39
  it "should set code" do
40
- @response.code.should.to_s == @response_object.code
40
+ expect(@response.code).to eq(@response_object.code)
41
41
  end
42
42
 
43
43
  it "should set code as a Fixnum" do
44
- @response.code.should be_an_instance_of(Fixnum)
44
+ expect(@response.code).to be_an_instance_of(Fixnum)
45
+ end
46
+
47
+ context 'when raise_on is supplied' do
48
+ let(:request) { HTTParty::Request.new(Net::HTTP::Get, '/', raise_on: [404]) }
49
+
50
+ context "and response's status code is in range" do
51
+ let(:body) { 'Not Found' }
52
+ let(:response) { Net::HTTPNotFound.new('1.1', 404, body) }
53
+
54
+ before do
55
+ allow(response).to receive(:body).and_return(body)
56
+ end
57
+
58
+ subject { described_class.new(request, response, @parsed_response) }
59
+
60
+ it 'throws exception' do
61
+ expect{ subject }.to raise_error(HTTParty::ResponseError, "Code 404 - #{body}")
62
+ end
63
+ end
64
+
65
+ context "and response's status code is not in range" do
66
+ subject { described_class.new(request, @response_object, @parsed_response) }
67
+
68
+ it 'does not throw exception' do
69
+ expect{ subject }.not_to raise_error(HTTParty::ResponseError)
70
+ end
71
+ end
45
72
  end
46
73
  end
47
74
 
48
75
  it "returns response headers" do
49
76
  response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
50
- response.headers.should == {'last-modified' => [@last_modified], 'content-length' => [@content_length]}
77
+ expect(response.headers).to eq({'last-modified' => [@last_modified], 'content-length' => [@content_length]})
51
78
  end
52
79
 
53
80
  it "should send missing methods to delegate" do
54
81
  response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
55
- response['foo'].should == 'bar'
82
+ expect(response['foo']).to eq('bar')
56
83
  end
57
84
 
58
85
  it "response to request" do
59
86
  response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
60
- response.respond_to?(:request).should be_true
87
+ expect(response.respond_to?(:request)).to be_truthy
61
88
  end
62
89
 
63
90
  it "responds to response" do
64
91
  response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
65
- response.respond_to?(:response).should be_true
92
+ expect(response.respond_to?(:response)).to be_truthy
66
93
  end
67
94
 
68
95
  it "responds to body" do
69
96
  response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
70
- response.respond_to?(:body).should be_true
97
+ expect(response.respond_to?(:body)).to be_truthy
71
98
  end
72
99
 
73
100
  it "responds to headers" do
74
101
  response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
75
- response.respond_to?(:headers).should be_true
102
+ expect(response.respond_to?(:headers)).to be_truthy
76
103
  end
77
104
 
78
105
  it "responds to parsed_response" do
79
106
  response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
80
- response.respond_to?(:parsed_response).should be_true
107
+ expect(response.respond_to?(:parsed_response)).to be_truthy
108
+ end
109
+
110
+ it "responds to predicates" do
111
+ response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
112
+ expect(response.respond_to?(:success?)).to be_truthy
81
113
  end
82
114
 
83
115
  it "responds to anything parsed_response responds to" do
84
116
  response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
85
- response.respond_to?(:[]).should be_true
117
+ expect(response.respond_to?(:[])).to be_truthy
86
118
  end
87
119
 
88
120
  it "should be able to iterate if it is array" do
89
121
  response = HTTParty::Response.new(@request_object, @response_object, lambda { [{'foo' => 'bar'}, {'foo' => 'baz'}] })
90
- response.size.should == 2
122
+ expect(response.size).to eq(2)
91
123
  expect {
92
124
  response.each { |item| }
93
125
  }.to_not raise_error
@@ -95,14 +127,14 @@ describe HTTParty::Response do
95
127
 
96
128
  it "allows headers to be accessed by mixed-case names in hash notation" do
97
129
  response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
98
- response.headers['Content-LENGTH'].should == @content_length
130
+ expect(response.headers['Content-LENGTH']).to eq(@content_length)
99
131
  end
100
132
 
101
133
  it "returns a comma-delimited value when multiple values exist" do
102
134
  @response_object.add_field 'set-cookie', 'csrf_id=12345; path=/'
103
135
  @response_object.add_field 'set-cookie', '_github_ses=A123CdE; path=/'
104
136
  response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
105
- response.headers['set-cookie'].should == "csrf_id=12345; path=/, _github_ses=A123CdE; path=/"
137
+ expect(response.headers['set-cookie']).to eq("csrf_id=12345; path=/, _github_ses=A123CdE; path=/")
106
138
  end
107
139
 
108
140
  # Backwards-compatibility - previously, #headers returned a Hash
@@ -110,14 +142,32 @@ describe HTTParty::Response do
110
142
  response = HTTParty::Response.new(@request_object, @response_object, @parsed_response)
111
143
  hash_methods = {}.methods - response.headers.methods
112
144
  hash_methods.each do |method_name|
113
- response.headers.respond_to?(method_name).should be_true
145
+ expect(response.headers.respond_to?(method_name)).to be_truthy
114
146
  end
115
147
  end
116
148
 
149
+ describe "#is_a?" do
150
+ subject { HTTParty::Response.new(@request_object, @response_object, @parsed_response) }
151
+
152
+ it { is_expected.to respond_to(:is_a?).with(1).arguments }
153
+ it { expect(subject.is_a?(HTTParty::Response)).to be_truthy }
154
+ it { expect(subject.is_a?(BasicObject)).to be_truthy }
155
+ it { expect(subject.is_a?(Object)).to be_falsey }
156
+ end
157
+
158
+ describe "#kind_of?" do
159
+ subject { HTTParty::Response.new(@request_object, @response_object, @parsed_response) }
160
+
161
+ it { is_expected.to respond_to(:kind_of?).with(1).arguments }
162
+ it { expect(subject.kind_of?(HTTParty::Response)).to be_truthy }
163
+ it { expect(subject.kind_of?(BasicObject)).to be_truthy }
164
+ it { expect(subject.kind_of?(Object)).to be_falsey }
165
+ end
166
+
117
167
  describe "semantic methods for response codes" do
118
168
  def response_mock(klass)
119
169
  response = klass.new('', '', '')
120
- response.stub(:body)
170
+ allow(response).to receive(:body)
121
171
  response
122
172
  end
123
173
 
@@ -125,76 +175,76 @@ describe HTTParty::Response do
125
175
  it "is information" do
126
176
  net_response = response_mock(Net::HTTPInformation)
127
177
  response = HTTParty::Response.new(@request_object, net_response, '')
128
- response.information?.should be_true
178
+ expect(response.information?).to be_truthy
129
179
  end
130
180
 
131
181
  it "is success" do
132
182
  net_response = response_mock(Net::HTTPSuccess)
133
183
  response = HTTParty::Response.new(@request_object, net_response, '')
134
- response.success?.should be_true
184
+ expect(response.success?).to be_truthy
135
185
  end
136
186
 
137
187
  it "is redirection" do
138
188
  net_response = response_mock(Net::HTTPRedirection)
139
189
  response = HTTParty::Response.new(@request_object, net_response, '')
140
- response.redirection?.should be_true
190
+ expect(response.redirection?).to be_truthy
141
191
  end
142
192
 
143
193
  it "is client error" do
144
194
  net_response = response_mock(Net::HTTPClientError)
145
195
  response = HTTParty::Response.new(@request_object, net_response, '')
146
- response.client_error?.should be_true
196
+ expect(response.client_error?).to be_truthy
147
197
  end
148
198
 
149
199
  it "is server error" do
150
200
  net_response = response_mock(Net::HTTPServerError)
151
201
  response = HTTParty::Response.new(@request_object, net_response, '')
152
- response.server_error?.should be_true
202
+ expect(response.server_error?).to be_truthy
153
203
  end
154
204
  end
155
205
 
156
206
  context "for specific codes" do
157
207
  SPECIFIC_CODES = {
158
- :accepted? => Net::HTTPAccepted,
159
- :bad_gateway? => Net::HTTPBadGateway,
160
- :bad_request? => Net::HTTPBadRequest,
161
- :conflict? => Net::HTTPConflict,
162
- :continue? => Net::HTTPContinue,
163
- :created? => Net::HTTPCreated,
164
- :expectation_failed? => Net::HTTPExpectationFailed,
165
- :forbidden? => Net::HTTPForbidden,
166
- :found? => Net::HTTPFound,
167
- :gateway_time_out? => Net::HTTPGatewayTimeOut,
168
- :gone? => Net::HTTPGone,
169
- :internal_server_error? => Net::HTTPInternalServerError,
170
- :length_required? => Net::HTTPLengthRequired,
171
- :method_not_allowed? => Net::HTTPMethodNotAllowed,
172
- :moved_permanently? => Net::HTTPMovedPermanently,
173
- :multiple_choice? => Net::HTTPMultipleChoice,
174
- :no_content? => Net::HTTPNoContent,
175
- :non_authoritative_information? => Net::HTTPNonAuthoritativeInformation,
176
- :not_acceptable? => Net::HTTPNotAcceptable,
177
- :not_found? => Net::HTTPNotFound,
178
- :not_implemented? => Net::HTTPNotImplemented,
179
- :not_modified? => Net::HTTPNotModified,
180
- :ok? => Net::HTTPOK,
181
- :partial_content? => Net::HTTPPartialContent,
182
- :payment_required? => Net::HTTPPaymentRequired,
183
- :precondition_failed? => Net::HTTPPreconditionFailed,
184
- :proxy_authentication_required? => Net::HTTPProxyAuthenticationRequired,
185
- :request_entity_too_large? => Net::HTTPRequestEntityTooLarge,
186
- :request_time_out? => Net::HTTPRequestTimeOut,
187
- :request_uri_too_long? => Net::HTTPRequestURITooLong,
188
- :requested_range_not_satisfiable? => Net::HTTPRequestedRangeNotSatisfiable,
189
- :reset_content? => Net::HTTPResetContent,
190
- :see_other? => Net::HTTPSeeOther,
191
- :service_unavailable? => Net::HTTPServiceUnavailable,
192
- :switch_protocol? => Net::HTTPSwitchProtocol,
193
- :temporary_redirect? => Net::HTTPTemporaryRedirect,
194
- :unauthorized? => Net::HTTPUnauthorized,
195
- :unsupported_media_type? => Net::HTTPUnsupportedMediaType,
196
- :use_proxy? => Net::HTTPUseProxy,
197
- :version_not_supported? => Net::HTTPVersionNotSupported
208
+ accepted?: Net::HTTPAccepted,
209
+ bad_gateway?: Net::HTTPBadGateway,
210
+ bad_request?: Net::HTTPBadRequest,
211
+ conflict?: Net::HTTPConflict,
212
+ continue?: Net::HTTPContinue,
213
+ created?: Net::HTTPCreated,
214
+ expectation_failed?: Net::HTTPExpectationFailed,
215
+ forbidden?: Net::HTTPForbidden,
216
+ found?: Net::HTTPFound,
217
+ gateway_time_out?: Net::HTTPGatewayTimeOut,
218
+ gone?: Net::HTTPGone,
219
+ internal_server_error?: Net::HTTPInternalServerError,
220
+ length_required?: Net::HTTPLengthRequired,
221
+ method_not_allowed?: Net::HTTPMethodNotAllowed,
222
+ moved_permanently?: Net::HTTPMovedPermanently,
223
+ multiple_choice?: Net::HTTPMultipleChoice,
224
+ no_content?: Net::HTTPNoContent,
225
+ non_authoritative_information?: Net::HTTPNonAuthoritativeInformation,
226
+ not_acceptable?: Net::HTTPNotAcceptable,
227
+ not_found?: Net::HTTPNotFound,
228
+ not_implemented?: Net::HTTPNotImplemented,
229
+ not_modified?: Net::HTTPNotModified,
230
+ ok?: Net::HTTPOK,
231
+ partial_content?: Net::HTTPPartialContent,
232
+ payment_required?: Net::HTTPPaymentRequired,
233
+ precondition_failed?: Net::HTTPPreconditionFailed,
234
+ proxy_authentication_required?: Net::HTTPProxyAuthenticationRequired,
235
+ request_entity_too_large?: Net::HTTPRequestEntityTooLarge,
236
+ request_time_out?: Net::HTTPRequestTimeOut,
237
+ request_uri_too_long?: Net::HTTPRequestURITooLong,
238
+ requested_range_not_satisfiable?: Net::HTTPRequestedRangeNotSatisfiable,
239
+ reset_content?: Net::HTTPResetContent,
240
+ see_other?: Net::HTTPSeeOther,
241
+ service_unavailable?: Net::HTTPServiceUnavailable,
242
+ switch_protocol?: Net::HTTPSwitchProtocol,
243
+ temporary_redirect?: Net::HTTPTemporaryRedirect,
244
+ unauthorized?: Net::HTTPUnauthorized,
245
+ unsupported_media_type?: Net::HTTPUnsupportedMediaType,
246
+ use_proxy?: Net::HTTPUseProxy,
247
+ version_not_supported?: Net::HTTPVersionNotSupported
198
248
  }
199
249
 
200
250
  # Ruby 2.0, new name for this response.
@@ -206,7 +256,7 @@ describe HTTParty::Response do
206
256
  it "responds to #{method}" do
207
257
  net_response = response_mock(klass)
208
258
  response = HTTParty::Response.new(@request_object, net_response, '')
209
- response.__send__(method).should be_true
259
+ expect(response.__send__(method)).to be_truthy
210
260
  end
211
261
  end
212
262
  end
@@ -215,7 +265,27 @@ describe HTTParty::Response do
215
265
  describe "headers" do
216
266
  it "can initialize without headers" do
217
267
  headers = HTTParty::Response::Headers.new
218
- headers.should == {}
268
+ expect(headers).to eq({})
269
+ end
270
+ end
271
+
272
+ describe "#tap" do
273
+ it "is possible to tap into a response" do
274
+ result = @response.tap(&:code)
275
+
276
+ expect(result).to eq @response
277
+ end
278
+ end
279
+
280
+ describe "#inspect" do
281
+ it "works" do
282
+ inspect = @response.inspect
283
+ expect(inspect).to include("HTTParty::Response:0x")
284
+ expect(inspect).to include("parsed_response={\"foo\"=>\"bar\"}")
285
+ expect(inspect).to include("@response=#<Net::HTTPOK 200 OK readbody=false>")
286
+ expect(inspect).to include("@headers={")
287
+ expect(inspect).to include("last-modified")
288
+ expect(inspect).to include("content-length")
219
289
  end
220
290
  end
221
291
  end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
2
 
3
- describe HTTParty::Request do
3
+ RSpec.describe HTTParty::Request do
4
4
  context "SSL certificate verification" do
5
5
  before do
6
6
  FakeWeb.allow_net_connect = true
@@ -11,64 +11,64 @@ describe HTTParty::Request do
11
11
  end
12
12
 
13
13
  it "should fail when no trusted CA list is specified, by default" do
14
- lambda do
14
+ expect do
15
15
  ssl_verify_test(nil, nil, "selfsigned.crt")
16
- end.should raise_error OpenSSL::SSL::SSLError
16
+ end.to raise_error OpenSSL::SSL::SSLError
17
17
  end
18
18
 
19
19
  it "should work when no trusted CA list is specified, when the verify option is set to false" do
20
- ssl_verify_test(nil, nil, "selfsigned.crt", :verify => false).should == {'success' => true}
20
+ expect(ssl_verify_test(nil, nil, "selfsigned.crt", verify: false).parsed_response).to eq({'success' => true})
21
21
  end
22
22
 
23
23
  it "should fail when no trusted CA list is specified, with a bogus hostname, by default" do
24
- lambda do
24
+ expect do
25
25
  ssl_verify_test(nil, nil, "bogushost.crt")
26
- end.should raise_error OpenSSL::SSL::SSLError
26
+ end.to raise_error OpenSSL::SSL::SSLError
27
27
  end
28
28
 
29
29
  it "should work when no trusted CA list is specified, even with a bogus hostname, when the verify option is set to true" do
30
- ssl_verify_test(nil, nil, "bogushost.crt", :verify => false).should == {'success' => true}
30
+ expect(ssl_verify_test(nil, nil, "bogushost.crt", verify: false).parsed_response).to eq({'success' => true})
31
31
  end
32
32
 
33
33
  it "should work when using ssl_ca_file with a self-signed CA" do
34
- ssl_verify_test(:ssl_ca_file, "selfsigned.crt", "selfsigned.crt").should == {'success' => true}
34
+ expect(ssl_verify_test(:ssl_ca_file, "selfsigned.crt", "selfsigned.crt").parsed_response).to eq({'success' => true})
35
35
  end
36
36
 
37
37
  it "should work when using ssl_ca_file with a certificate authority" do
38
- ssl_verify_test(:ssl_ca_file, "ca.crt", "server.crt").should == {'success' => true}
38
+ expect(ssl_verify_test(:ssl_ca_file, "ca.crt", "server.crt").parsed_response).to eq({'success' => true})
39
39
  end
40
40
 
41
41
  it "should work when using ssl_ca_path with a certificate authority" do
42
42
  http = Net::HTTP.new('www.google.com', 443)
43
- response = stub(Net::HTTPResponse, :[] => '', :body => '', :to_hash => {})
44
- http.stub(:request).and_return(response)
45
- Net::HTTP.should_receive(:new).with('www.google.com', 443).and_return(http)
46
- http.should_receive(:ca_path=).with('/foo/bar')
47
- HTTParty.get('https://www.google.com', :ssl_ca_path => '/foo/bar')
43
+ response = double(Net::HTTPResponse, :[] => '', body: '', to_hash: {})
44
+ allow(http).to receive(:request).and_return(response)
45
+ expect(Net::HTTP).to receive(:new).with('www.google.com', 443).and_return(http)
46
+ expect(http).to receive(:ca_path=).with('/foo/bar')
47
+ HTTParty.get('https://www.google.com', ssl_ca_path: '/foo/bar')
48
48
  end
49
49
 
50
50
  it "should fail when using ssl_ca_file and the server uses an unrecognized certificate authority" do
51
- lambda do
51
+ expect do
52
52
  ssl_verify_test(:ssl_ca_file, "ca.crt", "selfsigned.crt")
53
- end.should raise_error(OpenSSL::SSL::SSLError)
53
+ end.to raise_error(OpenSSL::SSL::SSLError)
54
54
  end
55
55
 
56
56
  it "should fail when using ssl_ca_path and the server uses an unrecognized certificate authority" do
57
- lambda do
57
+ expect do
58
58
  ssl_verify_test(:ssl_ca_path, ".", "selfsigned.crt")
59
- end.should raise_error(OpenSSL::SSL::SSLError)
59
+ end.to raise_error(OpenSSL::SSL::SSLError)
60
60
  end
61
61
 
62
62
  it "should fail when using ssl_ca_file and the server uses a bogus hostname" do
63
- lambda do
63
+ expect do
64
64
  ssl_verify_test(:ssl_ca_file, "ca.crt", "bogushost.crt")
65
- end.should raise_error(OpenSSL::SSL::SSLError)
65
+ end.to raise_error(OpenSSL::SSL::SSLError)
66
66
  end
67
67
 
68
68
  it "should fail when using ssl_ca_path and the server uses a bogus hostname" do
69
- lambda do
69
+ expect do
70
70
  ssl_verify_test(:ssl_ca_path, ".", "bogushost.crt")
71
- end.should raise_error(OpenSSL::SSL::SSLError)
71
+ end.to raise_error(OpenSSL::SSL::SSLError)
72
72
  end
73
73
  end
74
74
  end