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,67 +1,52 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
2
 
3
- describe HTTParty do
3
+ RSpec.describe HTTParty do
4
4
  before(:each) do
5
5
  @klass = Class.new
6
6
  @klass.instance_eval { include HTTParty }
7
7
  end
8
8
 
9
- describe "AllowedFormats deprecated" do
10
- before do
11
- Kernel.stub(:warn)
12
- end
13
-
14
- it "warns with a deprecation message" do
15
- Kernel.should_receive(:warn).with("Deprecated: Use HTTParty::Parser::SupportedFormats")
16
- HTTParty::AllowedFormats
17
- end
18
-
19
- it "returns HTTPart::Parser::SupportedFormats" do
20
- HTTParty::AllowedFormats.should == HTTParty::Parser::SupportedFormats
21
- end
22
- end
23
-
24
9
  describe "pem" do
25
10
  it 'should set the pem content' do
26
11
  @klass.pem 'PEM-CONTENT'
27
- @klass.default_options[:pem].should == 'PEM-CONTENT'
12
+ expect(@klass.default_options[:pem]).to eq('PEM-CONTENT')
28
13
  end
29
14
 
30
15
  it "should set the password to nil if it's not provided" do
31
16
  @klass.pem 'PEM-CONTENT'
32
- @klass.default_options[:pem_password].should be_nil
17
+ expect(@klass.default_options[:pem_password]).to be_nil
33
18
  end
34
19
 
35
20
  it 'should set the password' do
36
21
  @klass.pem 'PEM-CONTENT', 'PASSWORD'
37
- @klass.default_options[:pem_password].should == 'PASSWORD'
22
+ expect(@klass.default_options[:pem_password]).to eq('PASSWORD')
38
23
  end
39
24
  end
40
25
 
41
26
  describe "pkcs12" do
42
27
  it 'should set the p12 content' do
43
28
  @klass.pkcs12 'P12-CONTENT', 'PASSWORD'
44
- @klass.default_options[:p12].should == 'P12-CONTENT'
29
+ expect(@klass.default_options[:p12]).to eq('P12-CONTENT')
45
30
  end
46
31
 
47
32
  it 'should set the password' do
48
33
  @klass.pkcs12 'P12-CONTENT', 'PASSWORD'
49
- @klass.default_options[:p12_password].should == 'PASSWORD'
34
+ expect(@klass.default_options[:p12_password]).to eq('PASSWORD')
50
35
  end
51
36
  end
52
37
 
53
38
  describe 'ssl_version' do
54
39
  it 'should set the ssl_version content' do
55
40
  @klass.ssl_version :SSLv3
56
- @klass.default_options[:ssl_version].should == :SSLv3
41
+ expect(@klass.default_options[:ssl_version]).to eq(:SSLv3)
57
42
  end
58
43
  end
59
44
 
60
45
  describe 'ciphers' do
61
46
  it 'should set the ciphers content' do
62
- @klass.default_options[:ciphers].should be_nil
47
+ expect(@klass.default_options[:ciphers]).to be_nil
63
48
  @klass.ciphers 'RC4-SHA'
64
- @klass.default_options[:ciphers].should == 'RC4-SHA'
49
+ expect(@klass.default_options[:ciphers]).to eq('RC4-SHA')
65
50
  end
66
51
  end
67
52
 
@@ -69,15 +54,15 @@ describe HTTParty do
69
54
  it 'should set the address' do
70
55
  @klass.http_proxy 'proxy.foo.com', 80
71
56
  options = @klass.default_options
72
- options[:http_proxyaddr].should == 'proxy.foo.com'
73
- options[:http_proxyport].should == 80
57
+ expect(options[:http_proxyaddr]).to eq('proxy.foo.com')
58
+ expect(options[:http_proxyport]).to eq(80)
74
59
  end
75
60
 
76
61
  it 'should set the proxy user and pass when they are provided' do
77
62
  @klass.http_proxy 'proxy.foo.com', 80, 'user', 'pass'
78
63
  options = @klass.default_options
79
- options[:http_proxyuser].should == 'user'
80
- options[:http_proxypass].should == 'pass'
64
+ expect(options[:http_proxyuser]).to eq('user')
65
+ expect(options[:http_proxypass]).to eq('pass')
81
66
  end
82
67
  end
83
68
 
@@ -87,139 +72,146 @@ describe HTTParty do
87
72
  end
88
73
 
89
74
  it "should have reader" do
90
- @klass.base_uri.should == 'http://api.foo.com/v1'
75
+ expect(@klass.base_uri).to eq('http://api.foo.com/v1')
91
76
  end
92
77
 
93
78
  it 'should have writer' do
94
79
  @klass.base_uri('http://api.foobar.com')
95
- @klass.base_uri.should == 'http://api.foobar.com'
80
+ expect(@klass.base_uri).to eq('http://api.foobar.com')
96
81
  end
97
82
 
98
83
  it 'should not modify the parameter during assignment' do
99
84
  uri = 'http://api.foobar.com'
100
85
  @klass.base_uri(uri)
101
- uri.should == 'http://api.foobar.com'
86
+ expect(uri).to eq('http://api.foobar.com')
102
87
  end
103
88
  end
104
89
 
105
90
  describe ".disable_rails_query_string_format" do
106
91
  it "sets the query string normalizer to HTTParty::Request::NON_RAILS_QUERY_STRING_NORMALIZER" do
107
92
  @klass.disable_rails_query_string_format
108
- @klass.default_options[:query_string_normalizer].should == HTTParty::Request::NON_RAILS_QUERY_STRING_NORMALIZER
93
+ expect(@klass.default_options[:query_string_normalizer]).to eq(HTTParty::Request::NON_RAILS_QUERY_STRING_NORMALIZER)
109
94
  end
110
95
  end
111
96
 
112
97
  describe ".normalize_base_uri" do
113
98
  it "should add http if not present for non ssl requests" do
114
99
  uri = HTTParty.normalize_base_uri('api.foobar.com')
115
- uri.should == 'http://api.foobar.com'
100
+ expect(uri).to eq('http://api.foobar.com')
116
101
  end
117
102
 
118
103
  it "should add https if not present for ssl requests" do
119
104
  uri = HTTParty.normalize_base_uri('api.foo.com/v1:443')
120
- uri.should == 'https://api.foo.com/v1:443'
105
+ expect(uri).to eq('https://api.foo.com/v1:443')
121
106
  end
122
107
 
123
108
  it "should not remove https for ssl requests" do
124
109
  uri = HTTParty.normalize_base_uri('https://api.foo.com/v1:443')
125
- uri.should == 'https://api.foo.com/v1:443'
110
+ expect(uri).to eq('https://api.foo.com/v1:443')
126
111
  end
127
112
 
128
113
  it 'should not modify the parameter' do
129
114
  uri = 'http://api.foobar.com'
130
115
  HTTParty.normalize_base_uri(uri)
131
- uri.should == 'http://api.foobar.com'
116
+ expect(uri).to eq('http://api.foobar.com')
132
117
  end
133
118
 
134
119
  it "should not treat uri's with a port of 4430 as ssl" do
135
120
  uri = HTTParty.normalize_base_uri('http://api.foo.com:4430/v1')
136
- uri.should == 'http://api.foo.com:4430/v1'
121
+ expect(uri).to eq('http://api.foo.com:4430/v1')
137
122
  end
138
123
  end
139
124
 
140
125
  describe "headers" do
141
- def expect_headers(header={})
142
- HTTParty::Request.should_receive(:new) \
143
- .with(anything, anything, hash_including({ :headers => header })) \
144
- .and_return(mock("mock response", :perform => nil))
126
+ def expect_headers(header = {})
127
+ expect(HTTParty::Request).to receive(:new) \
128
+ .with(anything, anything, hash_including({ headers: header })) \
129
+ .and_return(double("mock response", perform: nil))
145
130
  end
146
131
 
147
132
  it "should default to empty hash" do
148
- @klass.headers.should == {}
133
+ expect(@klass.headers).to eq({})
149
134
  end
150
135
 
151
136
  it "should be able to be updated" do
152
- init_headers = {:foo => 'bar', :baz => 'spax'}
137
+ init_headers = {foo: 'bar', baz: 'spax'}
153
138
  @klass.headers init_headers
154
- @klass.headers.should == init_headers
139
+ expect(@klass.headers).to eq(init_headers)
155
140
  end
156
141
 
157
142
  it "uses the class headers when sending a request" do
158
- expect_headers(:foo => 'bar')
159
- @klass.headers(:foo => 'bar')
143
+ expect_headers(foo: 'bar')
144
+ @klass.headers(foo: 'bar')
160
145
  @klass.get('')
161
146
  end
162
147
 
163
148
  it "merges class headers with request headers" do
164
- expect_headers(:baz => 'spax', :foo => 'bar')
165
- @klass.headers(:foo => 'bar')
166
- @klass.get('', :headers => {:baz => 'spax'})
149
+ expect_headers(baz: 'spax', foo: 'bar')
150
+ @klass.headers(foo: 'bar')
151
+ @klass.get('', headers: {baz: 'spax'})
167
152
  end
168
153
 
169
154
  it 'overrides class headers with request headers' do
170
- expect_headers(:baz => 'spax', :foo => 'baz')
171
- @klass.headers(:foo => 'bar')
172
- @klass.get('', :headers => {:baz => 'spax', :foo => 'baz'})
155
+ expect_headers(baz: 'spax', foo: 'baz')
156
+ @klass.headers(foo: 'bar')
157
+ @klass.get('', headers: {baz: 'spax', foo: 'baz'})
173
158
  end
174
159
 
175
160
  context "with cookies" do
176
161
  it 'utilizes the class-level cookies' do
177
- expect_headers(:foo => 'bar', 'cookie' => 'type=snickerdoodle')
178
- @klass.headers(:foo => 'bar')
179
- @klass.cookies(:type => 'snickerdoodle')
162
+ expect_headers(foo: 'bar', 'cookie' => 'type=snickerdoodle')
163
+ @klass.headers(foo: 'bar')
164
+ @klass.cookies(type: 'snickerdoodle')
180
165
  @klass.get('')
181
166
  end
182
167
 
183
168
  it 'adds cookies to the headers' do
184
- expect_headers(:foo => 'bar', 'cookie' => 'type=snickerdoodle')
185
- @klass.headers(:foo => 'bar')
186
- @klass.get('', :cookies => {:type => 'snickerdoodle'})
169
+ expect_headers(foo: 'bar', 'cookie' => 'type=snickerdoodle')
170
+ @klass.headers(foo: 'bar')
171
+ @klass.get('', cookies: {type: 'snickerdoodle'})
172
+ end
173
+
174
+ it 'doesnt modify default_options' do
175
+ expect(@klass.headers).to eq({})
176
+ expect_headers('cookie' => 'type=snickerdoodle')
177
+ @klass.get('', cookies: {type: 'snickerdoodle'})
178
+ expect(@klass.default_options[:headers]).to eq({})
187
179
  end
188
180
 
189
181
  it 'adds optional cookies to the optional headers' do
190
- expect_headers(:baz => 'spax', 'cookie' => 'type=snickerdoodle')
191
- @klass.get('', :cookies => {:type => 'snickerdoodle'}, :headers => {:baz => 'spax'})
182
+ expect_headers(baz: 'spax', 'cookie' => 'type=snickerdoodle')
183
+ @klass.get('', cookies: {type: 'snickerdoodle'}, headers: {baz: 'spax'})
192
184
  end
193
185
  end
194
186
  end
195
187
 
196
188
  describe "cookies" do
197
189
  def expect_cookie_header(s)
198
- HTTParty::Request.should_receive(:new) \
199
- .with(anything, anything, hash_including({ :headers => { "cookie" => s } })) \
200
- .and_return(mock("mock response", :perform => nil))
190
+ expect(HTTParty::Request).to receive(:new) \
191
+ .with(anything, anything, hash_including({ headers: { "cookie" => s } })) \
192
+ .and_return(double("mock response", perform: nil))
201
193
  end
202
194
 
203
195
  it "should not be in the headers by default" do
204
- HTTParty::Request.stub!(:new).and_return(stub(nil, :perform => nil))
196
+ allow(HTTParty::Request).to receive(:new).and_return(double(nil, perform: nil))
205
197
  @klass.get("")
206
- @klass.headers.keys.should_not include("cookie")
198
+ expect(@klass.headers.keys).not_to include("cookie")
207
199
  end
208
200
 
209
201
  it "should raise an ArgumentError if passed a non-Hash" do
210
- lambda do
202
+ expect do
211
203
  @klass.cookies("nonsense")
212
- end.should raise_error(ArgumentError)
204
+ end.to raise_error(ArgumentError)
213
205
  end
214
206
 
215
207
  it "should allow a cookie to be specified with a one-off request" do
216
208
  expect_cookie_header "type=snickerdoodle"
217
- @klass.get("", :cookies => { :type => "snickerdoodle" })
209
+ @klass.get("", cookies: { type: "snickerdoodle" })
218
210
  end
219
211
 
220
212
  describe "when a cookie is set at the class level" do
221
213
  before(:each) do
222
- @klass.cookies({ :type => "snickerdoodle" })
214
+ @klass.cookies({ type: "snickerdoodle" })
223
215
  end
224
216
 
225
217
  it "should include that cookie in the request" do
@@ -237,7 +229,7 @@ describe HTTParty do
237
229
  it "should allow the class defaults to be overridden" do
238
230
  expect_cookie_header "type=chocolate_chip"
239
231
 
240
- @klass.get("", :cookies => { :type => "chocolate_chip" })
232
+ @klass.get("", cookies: { type: "chocolate_chip" })
241
233
  end
242
234
  end
243
235
 
@@ -245,11 +237,11 @@ describe HTTParty do
245
237
  before(:each) do
246
238
  @klass.instance_eval do
247
239
  def first_method
248
- get("first_method", :cookies => { :first_method_cookie => "foo" })
240
+ get("first_method", cookies: { first_method_cookie: "foo" })
249
241
  end
250
242
 
251
243
  def second_method
252
- get("second_method", :cookies => { :second_method_cookie => "foo" })
244
+ get("second_method", cookies: { second_method_cookie: "foo" })
253
245
  end
254
246
  end
255
247
  end
@@ -266,79 +258,79 @@ describe HTTParty do
266
258
 
267
259
  describe "default params" do
268
260
  it "should default to empty hash" do
269
- @klass.default_params.should == {}
261
+ expect(@klass.default_params).to eq({})
270
262
  end
271
263
 
272
264
  it "should be able to be updated" do
273
- new_defaults = {:foo => 'bar', :baz => 'spax'}
265
+ new_defaults = {foo: 'bar', baz: 'spax'}
274
266
  @klass.default_params new_defaults
275
- @klass.default_params.should == new_defaults
267
+ expect(@klass.default_params).to eq(new_defaults)
276
268
  end
277
269
  end
278
270
 
279
271
  describe "default timeout" do
280
272
  it "should default to nil" do
281
- @klass.default_options[:timeout].should == nil
273
+ expect(@klass.default_options[:timeout]).to eq(nil)
282
274
  end
283
275
 
284
276
  it "should support updating" do
285
277
  @klass.default_timeout 10
286
- @klass.default_options[:timeout].should == 10
278
+ expect(@klass.default_options[:timeout]).to eq(10)
287
279
  end
288
280
 
289
281
  it "should support floats" do
290
282
  @klass.default_timeout 0.5
291
- @klass.default_options[:timeout].should == 0.5
283
+ expect(@klass.default_options[:timeout]).to eq(0.5)
292
284
  end
293
285
  end
294
286
 
295
287
  describe "debug_output" do
296
288
  it "stores the given stream as a default_option" do
297
289
  @klass.debug_output $stdout
298
- @klass.default_options[:debug_output].should == $stdout
290
+ expect(@klass.default_options[:debug_output]).to eq($stdout)
299
291
  end
300
292
 
301
293
  it "stores the $stderr stream by default" do
302
294
  @klass.debug_output
303
- @klass.default_options[:debug_output].should == $stderr
295
+ expect(@klass.default_options[:debug_output]).to eq($stderr)
304
296
  end
305
297
  end
306
298
 
307
299
  describe "basic http authentication" do
308
300
  it "should work" do
309
301
  @klass.basic_auth 'foobar', 'secret'
310
- @klass.default_options[:basic_auth].should == {:username => 'foobar', :password => 'secret'}
302
+ expect(@klass.default_options[:basic_auth]).to eq({username: 'foobar', password: 'secret'})
311
303
  end
312
304
  end
313
305
 
314
306
  describe "digest http authentication" do
315
307
  it "should work" do
316
308
  @klass.digest_auth 'foobar', 'secret'
317
- @klass.default_options[:digest_auth].should == {:username => 'foobar', :password => 'secret'}
309
+ expect(@klass.default_options[:digest_auth]).to eq({username: 'foobar', password: 'secret'})
318
310
  end
319
311
  end
320
312
 
321
313
  describe "parser" do
322
314
  class CustomParser
323
315
  def self.parse(body)
324
- return {:sexy => true}
316
+ {sexy: true}
325
317
  end
326
318
  end
327
319
 
328
320
  let(:parser) do
329
- Proc.new{ |data, format| CustomParser.parse(data) }
321
+ proc { |data, format| CustomParser.parse(data) }
330
322
  end
331
323
 
332
324
  it "should set parser options" do
333
325
  @klass.parser parser
334
- @klass.default_options[:parser].should == parser
326
+ expect(@klass.default_options[:parser]).to eq(parser)
335
327
  end
336
328
 
337
329
  it "should be able parse response with custom parser" do
338
330
  @klass.parser parser
339
- FakeWeb.register_uri(:get, 'http://twitter.com/statuses/public_timeline.xml', :body => 'tweets')
331
+ FakeWeb.register_uri(:get, 'http://twitter.com/statuses/public_timeline.xml', body: 'tweets')
340
332
  custom_parsed_response = @klass.get('http://twitter.com/statuses/public_timeline.xml')
341
- custom_parsed_response[:sexy].should == true
333
+ expect(custom_parsed_response[:sexy]).to eq(true)
342
334
  end
343
335
 
344
336
  it "raises UnsupportedFormat when the parser cannot handle the format" do
@@ -355,122 +347,173 @@ describe HTTParty do
355
347
  expect do
356
348
  @klass.format :json
357
349
  @klass.parser lambda {|body, format|}
358
- end.to_not raise_error(HTTParty::UnsupportedFormat)
350
+ end.to_not raise_error
351
+ end
352
+ end
353
+
354
+ describe "uri_adapter" do
355
+
356
+ require 'forwardable'
357
+ class CustomURIAdaptor
358
+ extend Forwardable
359
+ def_delegators :@uri, :userinfo, :relative?, :query, :query=, :scheme, :path, :host, :port
360
+
361
+ def initialize uri
362
+ @uri = uri
363
+ end
364
+
365
+ def self.parse uri
366
+ new URI.parse uri
367
+ end
359
368
  end
369
+
370
+ let(:uri_adapter) { CustomURIAdaptor }
371
+
372
+ it "should set the uri_adapter" do
373
+ @klass.uri_adapter uri_adapter
374
+ expect(@klass.default_options[:uri_adapter]).to be uri_adapter
375
+ end
376
+
377
+ it "should raise an ArgumentError if uri_adapter doesn't implement parse method" do
378
+ expect do
379
+ @klass.uri_adapter double()
380
+ end.to raise_error(ArgumentError)
381
+ end
382
+
383
+
384
+ it "should process a request with a uri instance parsed from the uri_adapter" do
385
+ uri = 'http://foo.com/bar'
386
+ FakeWeb.register_uri(:get, uri, body: 'stuff')
387
+ @klass.uri_adapter uri_adapter
388
+ expect(@klass.get(uri).parsed_response).to eq('stuff')
389
+ end
390
+
360
391
  end
361
392
 
362
393
  describe "connection_adapter" do
363
394
  let(:uri) { 'http://google.com/api.json' }
364
- let(:connection_adapter) { mock('CustomConnectionAdapter') }
395
+ let(:connection_adapter) { double('CustomConnectionAdapter') }
365
396
 
366
397
  it "should set the connection_adapter" do
367
398
  @klass.connection_adapter connection_adapter
368
- @klass.default_options[:connection_adapter].should be connection_adapter
399
+ expect(@klass.default_options[:connection_adapter]).to be connection_adapter
369
400
  end
370
401
 
371
402
  it "should set the connection_adapter_options when provided" do
372
- options = {:foo => :bar}
403
+ options = {foo: :bar}
373
404
  @klass.connection_adapter connection_adapter, options
374
- @klass.default_options[:connection_adapter_options].should be options
405
+ expect(@klass.default_options[:connection_adapter_options]).to be options
375
406
  end
376
407
 
377
408
  it "should not set the connection_adapter_options when not provided" do
378
409
  @klass.connection_adapter connection_adapter
379
- @klass.default_options[:connection_adapter_options].should be_nil
410
+ expect(@klass.default_options[:connection_adapter_options]).to be_nil
380
411
  end
381
412
 
382
413
  it "should process a request with a connection from the adapter" do
383
- connection_adapter_options = {:foo => :bar}
384
- connection_adapter.should_receive(:call) do |u,o|
385
- o[:connection_adapter_options].should == connection_adapter_options
386
- HTTParty::ConnectionAdapter.call(u,o)
387
- end.with(URI.parse(uri), kind_of(Hash))
388
- FakeWeb.register_uri(:get, uri, :body => 'stuff')
414
+ connection_adapter_options = {foo: :bar}
415
+ expect(connection_adapter).to receive(:call) { |u, o|
416
+ expect(o[:connection_adapter_options]).to eq(connection_adapter_options)
417
+ HTTParty::ConnectionAdapter.call(u, o)
418
+ }.with(URI.parse(uri), kind_of(Hash))
419
+ FakeWeb.register_uri(:get, uri, body: 'stuff')
389
420
  @klass.connection_adapter connection_adapter, connection_adapter_options
390
- @klass.get(uri).should == 'stuff'
421
+ expect(@klass.get(uri).parsed_response).to eq('stuff')
391
422
  end
392
423
  end
393
424
 
394
425
  describe "format" do
395
426
  it "should allow xml" do
396
427
  @klass.format :xml
397
- @klass.default_options[:format].should == :xml
428
+ expect(@klass.default_options[:format]).to eq(:xml)
398
429
  end
399
430
 
400
431
  it "should allow csv" do
401
432
  @klass.format :csv
402
- @klass.default_options[:format].should == :csv
433
+ expect(@klass.default_options[:format]).to eq(:csv)
403
434
  end
404
435
 
405
436
  it "should allow json" do
406
437
  @klass.format :json
407
- @klass.default_options[:format].should == :json
438
+ expect(@klass.default_options[:format]).to eq(:json)
408
439
  end
409
440
 
410
441
  it "should allow plain" do
411
442
  @klass.format :plain
412
- @klass.default_options[:format].should == :plain
443
+ expect(@klass.default_options[:format]).to eq(:plain)
413
444
  end
414
445
 
415
446
  it 'should not allow funky format' do
416
- lambda do
447
+ expect do
417
448
  @klass.format :foobar
418
- end.should raise_error(HTTParty::UnsupportedFormat)
449
+ end.to raise_error(HTTParty::UnsupportedFormat)
419
450
  end
420
451
 
421
452
  it 'should only print each format once with an exception' do
422
- lambda do
453
+ expect do
423
454
  @klass.format :foobar
424
- end.should raise_error(HTTParty::UnsupportedFormat, "':foobar' Must be one of: csv, html, json, plain, xml")
455
+ end.to raise_error(HTTParty::UnsupportedFormat, "':foobar' Must be one of: csv, html, json, plain, xml")
425
456
  end
426
457
 
427
458
  it 'sets the default parser' do
428
- @klass.default_options[:parser].should be_nil
459
+ expect(@klass.default_options[:parser]).to be_nil
429
460
  @klass.format :json
430
- @klass.default_options[:parser].should == HTTParty::Parser
461
+ expect(@klass.default_options[:parser]).to eq(HTTParty::Parser)
431
462
  end
432
463
 
433
464
  it 'does not reset parser to the default parser' do
434
465
  my_parser = lambda {}
435
466
  @klass.parser my_parser
436
467
  @klass.format :json
437
- @klass.parser.should == my_parser
468
+ expect(@klass.parser).to eq(my_parser)
438
469
  end
439
470
  end
440
471
 
441
472
  describe "#no_follow" do
442
473
  it "sets no_follow to false by default" do
443
474
  @klass.no_follow
444
- @klass.default_options[:no_follow].should be_false
475
+ expect(@klass.default_options[:no_follow]).to be_falsey
445
476
  end
446
477
 
447
478
  it "sets the no_follow option to true" do
448
479
  @klass.no_follow true
449
- @klass.default_options[:no_follow].should be_true
480
+ expect(@klass.default_options[:no_follow]).to be_truthy
450
481
  end
451
482
  end
452
483
 
453
484
  describe "#maintain_method_across_redirects" do
454
485
  it "sets maintain_method_across_redirects to true by default" do
455
486
  @klass.maintain_method_across_redirects
456
- @klass.default_options[:maintain_method_across_redirects].should be_true
487
+ expect(@klass.default_options[:maintain_method_across_redirects]).to be_truthy
457
488
  end
458
489
 
459
490
  it "sets the maintain_method_across_redirects option to false" do
460
491
  @klass.maintain_method_across_redirects false
461
- @klass.default_options[:maintain_method_across_redirects].should be_false
492
+ expect(@klass.default_options[:maintain_method_across_redirects]).to be_falsey
493
+ end
494
+ end
495
+
496
+ describe "#resend_on_redirect" do
497
+ it "sets resend_on_redirect to true by default" do
498
+ @klass.resend_on_redirect
499
+ expect(@klass.default_options[:resend_on_redirect]).to be_truthy
500
+ end
501
+
502
+ it "sets resend_on_redirect option to false" do
503
+ @klass.resend_on_redirect false
504
+ expect(@klass.default_options[:resend_on_redirect]).to be_falsey
462
505
  end
463
506
  end
464
507
 
465
508
  describe ".follow_redirects" do
466
509
  it "sets follow redirects to true by default" do
467
510
  @klass.follow_redirects
468
- @klass.default_options[:follow_redirects].should be_true
511
+ expect(@klass.default_options[:follow_redirects]).to be_truthy
469
512
  end
470
513
 
471
514
  it "sets the follow_redirects option to false" do
472
515
  @klass.follow_redirects false
473
- @klass.default_options[:follow_redirects].should be_false
516
+ expect(@klass.default_options[:follow_redirects]).to be_falsey
474
517
  end
475
518
  end
476
519
 
@@ -478,70 +521,119 @@ describe HTTParty do
478
521
  it "sets the query_string_normalizer option" do
479
522
  normalizer = proc {}
480
523
  @klass.query_string_normalizer normalizer
481
- @klass.default_options[:query_string_normalizer].should == normalizer
524
+ expect(@klass.default_options[:query_string_normalizer]).to eq(normalizer)
525
+ end
526
+ end
527
+
528
+ describe ".raise_on" do
529
+ context 'when parameters is an array' do
530
+ it 'sets raise_on option' do
531
+ @klass.raise_on [500, 404]
532
+ expect(@klass.default_options[:raise_on]).to contain_exactly(404, 500)
533
+ end
534
+ end
535
+
536
+ context 'when parameters is a fixnum' do
537
+ it 'sets raise_on option' do
538
+ @klass.raise_on 404
539
+ expect(@klass.default_options[:raise_on]).to contain_exactly(404)
540
+ end
482
541
  end
483
542
  end
484
543
 
485
544
  describe "with explicit override of automatic redirect handling" do
486
545
  before do
487
- @request = HTTParty::Request.new(Net::HTTP::Get, 'http://api.foo.com/v1', :format => :xml, :no_follow => true)
546
+ @request = HTTParty::Request.new(Net::HTTP::Get, 'http://api.foo.com/v1', format: :xml, no_follow: true)
488
547
  @redirect = stub_response 'first redirect', 302
489
548
  @redirect['location'] = 'http://foo.com/bar'
490
- HTTParty::Request.stub(:new => @request)
549
+ allow(HTTParty::Request).to receive_messages(new: @request)
491
550
  end
492
551
 
493
552
  it "should fail with redirected GET" do
494
- lambda do
495
- @error = @klass.get('/foo', :no_follow => true)
496
- end.should raise_error(HTTParty::RedirectionTooDeep) {|e| e.response.body.should == 'first redirect'}
553
+ expect do
554
+ @error = @klass.get('/foo', no_follow: true)
555
+ end.to raise_error(HTTParty::RedirectionTooDeep) {|e| expect(e.response.body).to eq('first redirect')}
497
556
  end
498
557
 
499
558
  it "should fail with redirected POST" do
500
- lambda do
501
- @klass.post('/foo', :no_follow => true)
502
- end.should raise_error(HTTParty::RedirectionTooDeep) {|e| e.response.body.should == 'first redirect'}
559
+ expect do
560
+ @klass.post('/foo', no_follow: true)
561
+ end.to raise_error(HTTParty::RedirectionTooDeep) {|e| expect(e.response.body).to eq('first redirect')}
503
562
  end
504
563
 
505
564
  it "should fail with redirected PATCH" do
506
- lambda do
507
- @klass.patch('/foo', :no_follow => true)
508
- end.should raise_error(HTTParty::RedirectionTooDeep) {|e| e.response.body.should == 'first redirect'}
565
+ expect do
566
+ @klass.patch('/foo', no_follow: true)
567
+ end.to raise_error(HTTParty::RedirectionTooDeep) {|e| expect(e.response.body).to eq('first redirect')}
509
568
  end
510
569
 
511
570
  it "should fail with redirected DELETE" do
512
- lambda do
513
- @klass.delete('/foo', :no_follow => true)
514
- end.should raise_error(HTTParty::RedirectionTooDeep) {|e| e.response.body.should == 'first redirect'}
571
+ expect do
572
+ @klass.delete('/foo', no_follow: true)
573
+ end.to raise_error(HTTParty::RedirectionTooDeep) {|e| expect(e.response.body).to eq('first redirect')}
515
574
  end
516
575
 
517
576
  it "should fail with redirected MOVE" do
518
- lambda do
519
- @klass.move('/foo', :no_follow => true)
520
- end.should raise_error(HTTParty::RedirectionTooDeep) {|e| e.response.body.should == 'first redirect'}
577
+ expect do
578
+ @klass.move('/foo', no_follow: true)
579
+ end.to raise_error(HTTParty::RedirectionTooDeep) {|e| expect(e.response.body).to eq('first redirect')}
521
580
  end
522
581
 
523
582
  it "should fail with redirected COPY" do
524
- lambda do
525
- @klass.copy('/foo', :no_follow => true)
526
- end.should raise_error(HTTParty::RedirectionTooDeep) {|e| e.response.body.should == 'first redirect'}
583
+ expect do
584
+ @klass.copy('/foo', no_follow: true)
585
+ end.to raise_error(HTTParty::RedirectionTooDeep) {|e| expect(e.response.body).to eq('first redirect')}
527
586
  end
528
587
 
529
588
  it "should fail with redirected PUT" do
530
- lambda do
531
- @klass.put('/foo', :no_follow => true)
532
- end.should raise_error(HTTParty::RedirectionTooDeep) {|e| e.response.body.should == 'first redirect'}
589
+ expect do
590
+ @klass.put('/foo', no_follow: true)
591
+ end.to raise_error(HTTParty::RedirectionTooDeep) {|e| expect(e.response.body).to eq('first redirect')}
533
592
  end
534
593
 
535
594
  it "should fail with redirected HEAD" do
536
- lambda do
537
- @klass.head('/foo', :no_follow => true)
538
- end.should raise_error(HTTParty::RedirectionTooDeep) {|e| e.response.body.should == 'first redirect'}
595
+ expect do
596
+ @klass.head('/foo', no_follow: true)
597
+ end.to raise_error(HTTParty::RedirectionTooDeep) {|e| expect(e.response.body).to eq('first redirect')}
539
598
  end
540
599
 
541
600
  it "should fail with redirected OPTIONS" do
542
- lambda do
543
- @klass.options('/foo', :no_follow => true)
544
- end.should raise_error(HTTParty::RedirectionTooDeep) {|e| e.response.body.should == 'first redirect'}
601
+ expect do
602
+ @klass.options('/foo', no_follow: true)
603
+ end.to raise_error(HTTParty::RedirectionTooDeep) {|e| expect(e.response.body).to eq('first redirect')}
604
+ end
605
+
606
+ it "should fail with redirected MKCOL" do
607
+ expect do
608
+ @klass.mkcol('/foo', no_follow: true)
609
+ end.to raise_error(HTTParty::RedirectionTooDeep) {|e| expect(e.response.body).to eq('first redirect')}
610
+ end
611
+ end
612
+
613
+ describe "head requests should follow redirects requesting HEAD only" do
614
+ before do
615
+ allow(HTTParty::Request).to receive(:new).
616
+ and_return(double("mock response", perform: nil))
617
+ end
618
+
619
+ it "should remain HEAD request across redirects, unless specified otherwise" do
620
+ expect(@klass).to receive(:ensure_method_maintained_across_redirects).with({})
621
+ @klass.head('/foo')
622
+ end
623
+
624
+ end
625
+
626
+ describe "#ensure_method_maintained_across_redirects" do
627
+ it "should set maintain_method_across_redirects option if unspecified" do
628
+ options = {}
629
+ @klass.send(:ensure_method_maintained_across_redirects, options)
630
+ expect(options[:maintain_method_across_redirects]).to be_truthy
631
+ end
632
+
633
+ it "should not set maintain_method_across_redirects option if value is present" do
634
+ options = { maintain_method_across_redirects: false }
635
+ @klass.send(:ensure_method_maintained_across_redirects, options)
636
+ expect(options[:maintain_method_across_redirects]).to be_falsey
545
637
  end
546
638
  end
547
639
 
@@ -549,20 +641,20 @@ describe HTTParty do
549
641
  before(:each) do
550
642
  @klass.instance_eval do
551
643
  base_uri "http://first.com"
552
- default_params :one => 1
644
+ default_params one: 1
553
645
  end
554
646
 
555
647
  @additional_klass = Class.new
556
648
  @additional_klass.instance_eval do
557
649
  include HTTParty
558
650
  base_uri "http://second.com"
559
- default_params :two => 2
651
+ default_params two: 2
560
652
  end
561
653
  end
562
654
 
563
655
  it "should not run over each others options" do
564
- @klass.default_options.should == { :base_uri => 'http://first.com', :default_params => { :one => 1 } }
565
- @additional_klass.default_options.should == { :base_uri => 'http://second.com', :default_params => { :two => 2 } }
656
+ expect(@klass.default_options).to eq({ base_uri: 'http://first.com', default_params: { one: 1 } })
657
+ expect(@additional_klass.default_options).to eq({ base_uri: 'http://second.com', default_params: { two: 2 } })
566
658
  end
567
659
  end
568
660
 
@@ -580,71 +672,71 @@ describe HTTParty do
580
672
  end
581
673
 
582
674
  it "does not modify each others inherited attributes" do
583
- @child1.default_params :joe => "alive"
584
- @child2.default_params :joe => "dead"
675
+ @child1.default_params joe: "alive"
676
+ @child2.default_params joe: "dead"
585
677
 
586
- @child1.default_options.should == { :default_params => {:joe => "alive"} }
587
- @child2.default_options.should == { :default_params => {:joe => "dead"} }
678
+ expect(@child1.default_options).to eq({ default_params: {joe: "alive"} })
679
+ expect(@child2.default_options).to eq({ default_params: {joe: "dead"} })
588
680
 
589
- @parent.default_options.should == { }
681
+ expect(@parent.default_options).to eq({ })
590
682
  end
591
683
 
592
684
  it "inherits default_options from the superclass" do
593
685
  @parent.basic_auth 'user', 'password'
594
- @child1.default_options.should == {:basic_auth => {:username => 'user', :password => 'password'}}
686
+ expect(@child1.default_options).to eq({basic_auth: {username: 'user', password: 'password'}})
595
687
  @child1.basic_auth 'u', 'p' # modifying child1 has no effect on child2
596
- @child2.default_options.should == {:basic_auth => {:username => 'user', :password => 'password'}}
688
+ expect(@child2.default_options).to eq({basic_auth: {username: 'user', password: 'password'}})
597
689
  end
598
690
 
599
691
  it "doesn't modify the parent's default options" do
600
692
  @parent.basic_auth 'user', 'password'
601
693
 
602
694
  @child1.basic_auth 'u', 'p'
603
- @child1.default_options.should == {:basic_auth => {:username => 'u', :password => 'p'}}
695
+ expect(@child1.default_options).to eq({basic_auth: {username: 'u', password: 'p'}})
604
696
 
605
697
  @child1.basic_auth 'email', 'token'
606
- @child1.default_options.should == {:basic_auth => {:username => 'email', :password => 'token'}}
698
+ expect(@child1.default_options).to eq({basic_auth: {username: 'email', password: 'token'}})
607
699
 
608
- @parent.default_options.should == {:basic_auth => {:username => 'user', :password => 'password'}}
700
+ expect(@parent.default_options).to eq({basic_auth: {username: 'user', password: 'password'}})
609
701
  end
610
702
 
611
703
  it "doesn't modify hashes in the parent's default options" do
612
704
  @parent.headers 'Accept' => 'application/json'
613
705
  @child1.headers 'Accept' => 'application/xml'
614
706
 
615
- @parent.default_options[:headers].should == {'Accept' => 'application/json'}
616
- @child1.default_options[:headers].should == {'Accept' => 'application/xml'}
707
+ expect(@parent.default_options[:headers]).to eq({'Accept' => 'application/json'})
708
+ expect(@child1.default_options[:headers]).to eq({'Accept' => 'application/xml'})
617
709
  end
618
710
 
619
711
  it "works with lambda values" do
620
712
  @child1.default_options[:imaginary_option] = lambda { "This is a new lambda "}
621
- @child1.default_options[:imaginary_option].should be_a Proc
713
+ expect(@child1.default_options[:imaginary_option]).to be_a Proc
622
714
  end
623
715
 
624
716
  it 'should dup the proc on the child class' do
625
717
  imaginary_option = lambda { 2 * 3.14 }
626
718
  @parent.default_options[:imaginary_option] = imaginary_option
627
- @parent.default_options[:imaginary_option].call.should == imaginary_option.call
719
+ expect(@parent.default_options[:imaginary_option].call).to eq(imaginary_option.call)
628
720
  @child1.default_options[:imaginary_option]
629
- @child1.default_options[:imaginary_option].call.should == imaginary_option.call
630
- @child1.default_options[:imaginary_option].should_not be_equal imaginary_option
721
+ expect(@child1.default_options[:imaginary_option].call).to eq(imaginary_option.call)
722
+ expect(@child1.default_options[:imaginary_option]).not_to be_equal imaginary_option
631
723
  end
632
724
 
633
725
  it "inherits default_cookies from the parent class" do
634
726
  @parent.cookies 'type' => 'chocolate_chip'
635
- @child1.default_cookies.should == {"type" => "chocolate_chip"}
727
+ expect(@child1.default_cookies).to eq({"type" => "chocolate_chip"})
636
728
  @child1.cookies 'type' => 'snickerdoodle'
637
- @child1.default_cookies.should == {"type" => "snickerdoodle"}
638
- @child2.default_cookies.should == {"type" => "chocolate_chip"}
729
+ expect(@child1.default_cookies).to eq({"type" => "snickerdoodle"})
730
+ expect(@child2.default_cookies).to eq({"type" => "chocolate_chip"})
639
731
  end
640
732
 
641
733
  it "doesn't modify the parent's default cookies" do
642
734
  @parent.cookies 'type' => 'chocolate_chip'
643
735
 
644
736
  @child1.cookies 'type' => 'snickerdoodle'
645
- @child1.default_cookies.should == {"type" => "snickerdoodle"}
737
+ expect(@child1.default_cookies).to eq({"type" => "snickerdoodle"})
646
738
 
647
- @parent.default_cookies.should == {"type" => "chocolate_chip"}
739
+ expect(@parent.default_cookies).to eq({"type" => "chocolate_chip"})
648
740
  end
649
741
  end
650
742
 
@@ -661,30 +753,44 @@ describe HTTParty do
661
753
  end
662
754
  it "continues running the #inherited on the parent" do
663
755
  child = Class.new(@parent)
664
- child.instance_variable_get(:@grand_parent).should be_true
756
+ expect(child.instance_variable_get(:@grand_parent)).to be_truthy
665
757
  end
666
758
  end
667
759
 
668
760
  describe "#get" do
669
761
  it "should be able to get html" do
670
762
  stub_http_response_with('google.html')
671
- HTTParty.get('http://www.google.com').should == file_fixture('google.html')
763
+ expect(HTTParty.get('http://www.google.com').parsed_response).to eq(file_fixture('google.html'))
672
764
  end
673
765
 
674
766
  it "should be able to get chunked html" do
675
- chunks = ["Chunk1", "Chunk2", "Chunk3", "Chunk4"]
767
+ chunks = %w(Chunk1 Chunk2 Chunk3 Chunk4)
676
768
  stub_chunked_http_response_with(chunks)
677
769
 
678
- HTTParty.get('http://www.google.com') do |fragment|
679
- chunks.should include(fragment)
680
- end.should == chunks.join
770
+ expect(
771
+ HTTParty.get('http://www.google.com') do |fragment|
772
+ expect(chunks).to include(fragment)
773
+ end.parsed_response
774
+ ).to eq(chunks.join)
775
+ end
776
+
777
+ it "should return an empty body if stream_body option is turned on" do
778
+ chunks = %w(Chunk1 Chunk2 Chunk3 Chunk4)
779
+ options = {stream_body: true, format: 'html'}
780
+ stub_chunked_http_response_with(chunks, options)
781
+
782
+ expect(
783
+ HTTParty.get('http://www.google.com', options) do |fragment|
784
+ expect(chunks).to include(fragment)
785
+ end.parsed_response
786
+ ).to eq(nil)
681
787
  end
682
788
 
683
789
  it "should be able parse response type json automatically" do
684
790
  stub_http_response_with('twitter.json')
685
791
  tweets = HTTParty.get('http://twitter.com/statuses/public_timeline.json')
686
- tweets.size.should == 20
687
- tweets.first['user'].should == {
792
+ expect(tweets.size).to eq(20)
793
+ expect(tweets.first['user']).to eq({
688
794
  "name" => "Pyk",
689
795
  "url" => nil,
690
796
  "id" => "7694602",
@@ -694,14 +800,14 @@ describe HTTParty do
694
800
  "followers_count" => 1,
695
801
  "location" => "Opera Plaza, California",
696
802
  "profile_image_url" => "http://static.twitter.com/images/default_profile_normal.png"
697
- }
803
+ })
698
804
  end
699
805
 
700
806
  it "should be able parse response type xml automatically" do
701
807
  stub_http_response_with('twitter.xml')
702
808
  tweets = HTTParty.get('http://twitter.com/statuses/public_timeline.xml')
703
- tweets['statuses'].size.should == 20
704
- tweets['statuses'].first['user'].should == {
809
+ expect(tweets['statuses'].size).to eq(20)
810
+ expect(tweets['statuses'].first['user']).to eq({
705
811
  "name" => "Magic 8 Bot",
706
812
  "url" => nil,
707
813
  "id" => "17656026",
@@ -711,54 +817,56 @@ describe HTTParty do
711
817
  "followers_count" => "90",
712
818
  "profile_image_url" => "http://s3.amazonaws.com/twitter_production/profile_images/65565851/8ball_large_normal.jpg",
713
819
  "location" => nil
714
- }
820
+ })
715
821
  end
716
822
 
717
823
  it "should be able parse response type csv automatically" do
718
824
  stub_http_response_with('twitter.csv')
719
825
  profile = HTTParty.get('http://twitter.com/statuses/profile.csv')
720
- profile.size.should == 2
721
- profile[0].should == ["name","url","id","description","protected","screen_name","followers_count","profile_image_url","location"]
722
- profile[1].should == ["Magic 8 Bot",nil,"17656026","ask me a question","false","magic8bot","90","http://s3.amazonaws.com/twitter_production/profile_images/65565851/8ball_large_normal.jpg",nil]
826
+ expect(profile.size).to eq(2)
827
+ expect(profile[0]).to eq(%w(name url id description protected screen_name followers_count profile_image_url location))
828
+ expect(profile[1]).to eq(["Magic 8 Bot", nil, "17656026", "ask me a question", "false", "magic8bot", "90", "http://s3.amazonaws.com/twitter_production/profile_images/65565851/8ball_large_normal.jpg", nil])
723
829
  end
724
830
 
725
831
  it "should not get undefined method add_node for nil class for the following xml" do
726
832
  stub_http_response_with('undefined_method_add_node_for_nil.xml')
727
833
  result = HTTParty.get('http://foobar.com')
728
- result.should == {"Entities"=>{"href"=>"https://s3-sandbox.parature.com/api/v1/5578/5633/Account", "results"=>"0", "total"=>"0", "page_size"=>"25", "page"=>"1"}}
834
+ expect(result.parsed_response).to eq({"Entities" => {"href" => "https://s3-sandbox.parature.com/api/v1/5578/5633/Account", "results" => "0", "total" => "0", "page_size" => "25", "page" => "1"}})
729
835
  end
730
836
 
731
837
  it "should parse empty response fine" do
732
838
  stub_http_response_with('empty.xml')
733
839
  result = HTTParty.get('http://foobar.com')
734
- result.should be_nil
840
+ expect(result).to be_nil
735
841
  end
736
842
 
737
843
  it "should accept http URIs" do
738
844
  stub_http_response_with('google.html')
739
- lambda do
845
+ expect do
740
846
  HTTParty.get('http://google.com')
741
- end.should_not raise_error(HTTParty::UnsupportedURIScheme)
847
+ end.not_to raise_error
742
848
  end
743
849
 
744
850
  it "should accept https URIs" do
745
851
  stub_http_response_with('google.html')
746
- lambda do
852
+ expect do
747
853
  HTTParty.get('https://google.com')
748
- end.should_not raise_error(HTTParty::UnsupportedURIScheme)
854
+ end.not_to raise_error
749
855
  end
750
856
 
751
857
  it "should accept webcal URIs" do
752
- stub_http_response_with('google.html')
753
- lambda do
754
- HTTParty.get('webcal://google.com')
755
- end.should_not raise_error(HTTParty::UnsupportedURIScheme)
858
+ uri = 'http://google.com/'
859
+ FakeWeb.register_uri(:get, uri, body: 'stuff')
860
+ uri = 'webcal://google.com/'
861
+ expect do
862
+ HTTParty.get(uri)
863
+ end.not_to raise_error
756
864
  end
757
865
 
758
866
  it "should raise an InvalidURIError on URIs that can't be parsed at all" do
759
- lambda do
867
+ expect do
760
868
  HTTParty.get("It's the one that says 'Bad URI'")
761
- end.should raise_error(URI::InvalidURIError)
869
+ end.to raise_error(URI::InvalidURIError)
762
870
  end
763
871
  end
764
872
  end