faraday_middleware 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +1 -1
- data/faraday_middleware.gemspec +1 -4
- data/lib/faraday_middleware/instrumentation.rb +1 -1
- data/lib/faraday_middleware/rack_compatible.rb +1 -1
- data/lib/faraday_middleware/response/follow_redirects.rb +19 -5
- data/lib/faraday_middleware/response/parse_yaml.rb +17 -0
- data/lib/faraday_middleware/version.rb +1 -1
- metadata +4 -36
- data/Rakefile +0 -28
- data/spec/caching_spec.rb +0 -170
- data/spec/chunked_spec.rb +0 -78
- data/spec/encode_json_spec.rb +0 -95
- data/spec/follow_redirects_spec.rb +0 -221
- data/spec/helper.rb +0 -59
- data/spec/mashify_spec.rb +0 -70
- data/spec/method_override_spec.rb +0 -92
- data/spec/oauth2_spec.rb +0 -118
- data/spec/oauth_spec.rb +0 -151
- data/spec/parse_dates_spec.rb +0 -44
- data/spec/parse_json_spec.rb +0 -112
- data/spec/parse_marshal_spec.rb +0 -16
- data/spec/parse_xml_spec.rb +0 -71
- data/spec/parse_yaml_spec.rb +0 -53
- data/spec/rashify_spec.rb +0 -47
data/spec/parse_yaml_spec.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
require 'faraday_middleware/response/parse_yaml'
|
3
|
-
|
4
|
-
describe FaradayMiddleware::ParseYaml, :type => :response do
|
5
|
-
context "no type matching" do
|
6
|
-
it "doesn't change nil body" do
|
7
|
-
expect(process(nil).body).to be_nil
|
8
|
-
end
|
9
|
-
|
10
|
-
it "returns false for empty body" do
|
11
|
-
expect(process('').body).to be_false
|
12
|
-
end
|
13
|
-
|
14
|
-
it "parses yaml body" do
|
15
|
-
response = process('a: 1')
|
16
|
-
expect(response.body).to eq('a' => 1)
|
17
|
-
expect(response.env[:raw_body]).to be_nil
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context "with preserving raw" do
|
22
|
-
let(:options) { {:preserve_raw => true} }
|
23
|
-
|
24
|
-
it "parses yaml body" do
|
25
|
-
response = process('a: 1')
|
26
|
-
expect(response.body).to eq('a' => 1)
|
27
|
-
expect(response.env[:raw_body]).to eq('a: 1')
|
28
|
-
end
|
29
|
-
|
30
|
-
it "can opt out of preserving raw" do
|
31
|
-
response = process('a: 1', nil, :preserve_raw => false)
|
32
|
-
expect(response.env[:raw_body]).to be_nil
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context "with regexp type matching" do
|
37
|
-
let(:options) { {:content_type => /\byaml$/} }
|
38
|
-
|
39
|
-
it "parses json body of correct type" do
|
40
|
-
response = process('a: 1', 'application/x-yaml')
|
41
|
-
expect(response.body).to eq('a' => 1)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "ignores json body of incorrect type" do
|
45
|
-
response = process('a: 1', 'text/yaml-xml')
|
46
|
-
expect(response.body).to eq('a: 1')
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
it "chokes on invalid yaml" do
|
51
|
-
expect{ process('{!') }.to raise_error(Faraday::Error::ParsingError)
|
52
|
-
end
|
53
|
-
end
|
data/spec/rashify_spec.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
require 'faraday_middleware/response/rashify'
|
3
|
-
|
4
|
-
describe FaradayMiddleware::Rashify do
|
5
|
-
context "when used", :type => :response do
|
6
|
-
it "creates a Hashie::Rash from the body" do
|
7
|
-
body = { "name" => "Erik Michaels-Ober", "username" => "sferik" }
|
8
|
-
me = process(body).body
|
9
|
-
expect(me.name).to eq("Erik Michaels-Ober")
|
10
|
-
expect(me.username).to eq("sferik")
|
11
|
-
end
|
12
|
-
|
13
|
-
it "handles strings" do
|
14
|
-
body = "Most amazing string EVER"
|
15
|
-
me = process(body).body
|
16
|
-
expect(me).to eq("Most amazing string EVER")
|
17
|
-
end
|
18
|
-
|
19
|
-
it "handles hashes and decamelcase the keys" do
|
20
|
-
body = { "name" => "Erik Michaels-Ober", "userName" => "sferik" }
|
21
|
-
me = process(body).body
|
22
|
-
expect(me.name).to eq('Erik Michaels-Ober')
|
23
|
-
expect(me.user_name).to eq('sferik')
|
24
|
-
end
|
25
|
-
|
26
|
-
it "handles arrays" do
|
27
|
-
body = [123, 456]
|
28
|
-
values = process(body).body
|
29
|
-
expect(values).to eq([123, 456])
|
30
|
-
end
|
31
|
-
|
32
|
-
it "handles arrays of hashes" do
|
33
|
-
body = [{ "username" => "sferik" }, { "username" => "pengwynn" }]
|
34
|
-
us = process(body).body
|
35
|
-
expect(us.first.username).to eq('sferik')
|
36
|
-
expect(us.last.username).to eq('pengwynn')
|
37
|
-
end
|
38
|
-
|
39
|
-
it "handles mixed arrays" do
|
40
|
-
body = [123, { "username" => "sferik" }, 456]
|
41
|
-
values = process(body).body
|
42
|
-
expect(values.first).to eq(123)
|
43
|
-
expect(values.last).to eq(456)
|
44
|
-
expect(values[1].username).to eq('sferik')
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|