faraday_middleware 0.9.1 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
@@ -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