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