httparty 0.13.7 → 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.
- checksums.yaml +4 -4
- data/.travis.yml +4 -2
- data/Gemfile +2 -2
- data/History +8 -0
- data/README.md +1 -0
- data/docs/README.md +100 -0
- data/examples/tripit_sign_in.rb +17 -6
- data/features/steps/httparty_response_steps.rb +8 -4
- data/features/steps/remote_service_steps.rb +6 -4
- data/httparty.gemspec +0 -1
- data/lib/httparty.rb +20 -5
- data/lib/httparty/connection_adapter.rb +13 -4
- data/lib/httparty/cookie_hash.rb +1 -1
- data/lib/httparty/exceptions.rb +4 -1
- data/lib/httparty/hash_conversions.rb +5 -1
- data/lib/httparty/logger/curl_formatter.rb +66 -23
- data/lib/httparty/net_digest_auth.rb +4 -2
- data/lib/httparty/request.rb +26 -3
- data/lib/httparty/response.rb +22 -2
- data/lib/httparty/version.rb +1 -1
- data/spec/httparty/connection_adapter_spec.rb +28 -1
- data/spec/httparty/cookie_hash_spec.rb +18 -1
- data/spec/httparty/exception_spec.rb +7 -0
- data/spec/httparty/hash_conversions_spec.rb +8 -0
- data/spec/httparty/logger/curl_formatter_spec.rb +101 -0
- data/spec/httparty/net_digest_auth_spec.rb +10 -0
- data/spec/httparty/request_spec.rb +118 -8
- data/spec/httparty/response_spec.rb +50 -0
- data/spec/httparty_spec.rb +22 -0
- metadata +4 -17
@@ -43,6 +43,33 @@ RSpec.describe HTTParty::Response do
|
|
43
43
|
it "should set code as a Fixnum" do
|
44
44
|
expect(@response.code).to be_an_instance_of(Fixnum)
|
45
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
|
72
|
+
end
|
46
73
|
end
|
47
74
|
|
48
75
|
it "returns response headers" do
|
@@ -80,6 +107,11 @@ RSpec.describe HTTParty::Response do
|
|
80
107
|
expect(response.respond_to?(:parsed_response)).to be_truthy
|
81
108
|
end
|
82
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
|
113
|
+
end
|
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
117
|
expect(response.respond_to?(:[])).to be_truthy
|
@@ -114,6 +146,24 @@ RSpec.describe HTTParty::Response do
|
|
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('', '', '')
|
data/spec/httparty_spec.rb
CHANGED
@@ -525,6 +525,22 @@ RSpec.describe HTTParty do
|
|
525
525
|
end
|
526
526
|
end
|
527
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
|
541
|
+
end
|
542
|
+
end
|
543
|
+
|
528
544
|
describe "with explicit override of automatic redirect handling" do
|
529
545
|
before do
|
530
546
|
@request = HTTParty::Request.new(Net::HTTP::Get, 'http://api.foo.com/v1', format: :xml, no_follow: true)
|
@@ -586,6 +602,12 @@ RSpec.describe HTTParty do
|
|
586
602
|
@klass.options('/foo', no_follow: true)
|
587
603
|
end.to raise_error(HTTParty::RedirectionTooDeep) {|e| expect(e.response.body).to eq('first redirect')}
|
588
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
|
589
611
|
end
|
590
612
|
|
591
613
|
describe "head requests should follow redirects requesting HEAD only" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httparty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
@@ -9,22 +9,8 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-07-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: json
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - "~>"
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '1.8'
|
21
|
-
type: :runtime
|
22
|
-
prerelease: false
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - "~>"
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: '1.8'
|
28
14
|
- !ruby/object:Gem::Dependency
|
29
15
|
name: multi_xml
|
30
16
|
requirement: !ruby/object:Gem::Requirement
|
@@ -61,6 +47,7 @@ files:
|
|
61
47
|
- Rakefile
|
62
48
|
- bin/httparty
|
63
49
|
- cucumber.yml
|
50
|
+
- docs/README.md
|
64
51
|
- examples/README.md
|
65
52
|
- examples/aaws.rb
|
66
53
|
- examples/basic.rb
|
@@ -163,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
150
|
version: '0'
|
164
151
|
requirements: []
|
165
152
|
rubyforge_project:
|
166
|
-
rubygems_version: 2.
|
153
|
+
rubygems_version: 2.4.5.1
|
167
154
|
signing_key:
|
168
155
|
specification_version: 4
|
169
156
|
summary: Makes http fun! Also, makes consuming restful web services dead easy.
|