httparty 0.10.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 (79) hide show
  1. checksums.yaml +7 -0
  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 +5 -4
  7. data/CONTRIBUTING.md +23 -0
  8. data/Gemfile +9 -5
  9. data/Guardfile +3 -3
  10. data/History +109 -8
  11. data/README.md +21 -21
  12. data/Rakefile +5 -10
  13. data/bin/httparty +21 -14
  14. data/docs/README.md +100 -0
  15. data/examples/README.md +67 -0
  16. data/examples/aaws.rb +9 -9
  17. data/examples/basic.rb +6 -10
  18. data/examples/crack.rb +3 -3
  19. data/examples/custom_parsers.rb +1 -4
  20. data/examples/delicious.rb +12 -12
  21. data/examples/google.rb +2 -2
  22. data/examples/headers_and_user_agents.rb +2 -2
  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 +11 -11
  30. data/examples/whoismyrep.rb +2 -2
  31. data/features/command_line.feature +90 -2
  32. data/features/digest_authentication.feature +10 -0
  33. data/features/handles_compressed_responses.feature +8 -0
  34. data/features/handles_multiple_formats.feature +23 -0
  35. data/features/steps/env.rb +16 -11
  36. data/features/steps/httparty_response_steps.rb +40 -10
  37. data/features/steps/httparty_steps.rb +19 -3
  38. data/features/steps/mongrel_helper.rb +35 -2
  39. data/features/steps/remote_service_steps.rb +31 -8
  40. data/features/supports_read_timeout_option.feature +13 -0
  41. data/httparty.gemspec +9 -6
  42. data/lib/httparty/connection_adapter.rb +76 -11
  43. data/lib/httparty/cookie_hash.rb +3 -4
  44. data/lib/httparty/exceptions.rb +10 -4
  45. data/lib/httparty/hash_conversions.rb +19 -17
  46. data/lib/httparty/logger/apache_formatter.rb +22 -0
  47. data/lib/httparty/logger/curl_formatter.rb +91 -0
  48. data/lib/httparty/logger/logger.rb +26 -0
  49. data/lib/httparty/module_inheritable_attributes.rb +1 -1
  50. data/lib/httparty/net_digest_auth.rb +69 -18
  51. data/lib/httparty/parser.rb +15 -11
  52. data/lib/httparty/request.rb +186 -47
  53. data/lib/httparty/response/headers.rb +2 -2
  54. data/lib/httparty/response.rb +44 -9
  55. data/lib/httparty/version.rb +1 -1
  56. data/lib/httparty.rb +187 -65
  57. data/script/release +42 -0
  58. data/spec/fixtures/twitter.csv +2 -0
  59. data/spec/httparty/connection_adapter_spec.rb +334 -62
  60. data/spec/httparty/cookie_hash_spec.rb +53 -23
  61. data/spec/httparty/exception_spec.rb +45 -0
  62. data/spec/httparty/hash_conversions_spec.rb +49 -0
  63. data/spec/httparty/logger/apache_formatter_spec.rb +41 -0
  64. data/spec/httparty/logger/curl_formatter_spec.rb +119 -0
  65. data/spec/httparty/logger/logger_spec.rb +38 -0
  66. data/spec/httparty/net_digest_auth_spec.rb +148 -23
  67. data/spec/httparty/parser_spec.rb +48 -41
  68. data/spec/httparty/request_spec.rb +845 -151
  69. data/spec/httparty/response_spec.rb +147 -70
  70. data/spec/httparty/ssl_spec.rb +33 -21
  71. data/spec/httparty_spec.rb +337 -186
  72. data/spec/spec_helper.rb +38 -9
  73. data/spec/support/ssl_test_helper.rb +10 -10
  74. data/spec/support/ssl_test_server.rb +21 -21
  75. data/spec/support/stub_response.rb +20 -14
  76. data/website/index.html +3 -3
  77. metadata +46 -37
  78. data/lib/httparty/core_extensions.rb +0 -32
  79. 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,81 +175,88 @@ 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
198
- }.each do |method, klass|
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
248
+ }
249
+
250
+ # Ruby 2.0, new name for this response.
251
+ if RUBY_VERSION >= "2.0.0" && ::RUBY_PLATFORM != "java"
252
+ SPECIFIC_CODES[:multiple_choices?] = Net::HTTPMultipleChoices
253
+ end
254
+
255
+ SPECIFIC_CODES.each do |method, klass|
199
256
  it "responds to #{method}" do
200
257
  net_response = response_mock(klass)
201
258
  response = HTTParty::Response.new(@request_object, net_response, '')
202
- response.__send__(method).should be_true
259
+ expect(response.__send__(method)).to be_truthy
203
260
  end
204
261
  end
205
262
  end
@@ -208,7 +265,27 @@ describe HTTParty::Response do
208
265
  describe "headers" do
209
266
  it "can initialize without headers" do
210
267
  headers = HTTParty::Response::Headers.new
211
- 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")
212
289
  end
213
290
  end
214
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
@@ -10,53 +10,65 @@ describe HTTParty::Request do
10
10
  FakeWeb.allow_net_connect = false
11
11
  end
12
12
 
13
- it "should work when no trusted CA list is specified" do
14
- ssl_verify_test(nil, nil, "selfsigned.crt").should == {'success' => true}
13
+ it "should fail when no trusted CA list is specified, by default" do
14
+ expect do
15
+ ssl_verify_test(nil, nil, "selfsigned.crt")
16
+ end.to raise_error OpenSSL::SSL::SSLError
15
17
  end
16
18
 
17
- it "should work when no trusted CA list is specified, even with a bogus hostname" do
18
- ssl_verify_test(nil, nil, "bogushost.crt").should == {'success' => true}
19
+ it "should work when no trusted CA list is specified, when the verify option is set to false" do
20
+ expect(ssl_verify_test(nil, nil, "selfsigned.crt", verify: false).parsed_response).to eq({'success' => true})
21
+ end
22
+
23
+ it "should fail when no trusted CA list is specified, with a bogus hostname, by default" do
24
+ expect do
25
+ ssl_verify_test(nil, nil, "bogushost.crt")
26
+ end.to raise_error OpenSSL::SSL::SSLError
27
+ end
28
+
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
+ expect(ssl_verify_test(nil, nil, "bogushost.crt", verify: false).parsed_response).to eq({'success' => true})
19
31
  end
20
32
 
21
33
  it "should work when using ssl_ca_file with a self-signed CA" do
22
- 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})
23
35
  end
24
36
 
25
37
  it "should work when using ssl_ca_file with a certificate authority" do
26
- 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})
27
39
  end
28
40
 
29
41
  it "should work when using ssl_ca_path with a certificate authority" do
30
- http = Net::HTTP.new('www.google.com', 443, nil, nil, nil, nil)
31
- response = stub(Net::HTTPResponse, :[] => '', :body => '', :to_hash => {})
32
- http.stub(:request).and_return(response)
33
- Net::HTTP.should_receive(:new).with('www.google.com', 443, nil, nil, nil, nil).and_return(http)
34
- http.should_receive(:ca_path=).with('/foo/bar')
35
- HTTParty.get('https://www.google.com', :ssl_ca_path => '/foo/bar')
42
+ http = Net::HTTP.new('www.google.com', 443)
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')
36
48
  end
37
49
 
38
50
  it "should fail when using ssl_ca_file and the server uses an unrecognized certificate authority" do
39
- lambda do
51
+ expect do
40
52
  ssl_verify_test(:ssl_ca_file, "ca.crt", "selfsigned.crt")
41
- end.should raise_error(OpenSSL::SSL::SSLError)
53
+ end.to raise_error(OpenSSL::SSL::SSLError)
42
54
  end
43
55
 
44
56
  it "should fail when using ssl_ca_path and the server uses an unrecognized certificate authority" do
45
- lambda do
57
+ expect do
46
58
  ssl_verify_test(:ssl_ca_path, ".", "selfsigned.crt")
47
- end.should raise_error(OpenSSL::SSL::SSLError)
59
+ end.to raise_error(OpenSSL::SSL::SSLError)
48
60
  end
49
61
 
50
62
  it "should fail when using ssl_ca_file and the server uses a bogus hostname" do
51
- lambda do
63
+ expect do
52
64
  ssl_verify_test(:ssl_ca_file, "ca.crt", "bogushost.crt")
53
- end.should raise_error(OpenSSL::SSL::SSLError)
65
+ end.to raise_error(OpenSSL::SSL::SSLError)
54
66
  end
55
67
 
56
68
  it "should fail when using ssl_ca_path and the server uses a bogus hostname" do
57
- lambda do
69
+ expect do
58
70
  ssl_verify_test(:ssl_ca_path, ".", "bogushost.crt")
59
- end.should raise_error(OpenSSL::SSL::SSLError)
71
+ end.to raise_error(OpenSSL::SSL::SSLError)
60
72
  end
61
73
  end
62
74
  end