|
6 | 6 | context 'with a cortex error response' do |
7 | 7 | it 'should return the error object' do |
8 | 8 | body = {'error' => 'Validation error or something'} |
9 | | - response = OpenStruct.new(:status => 422, :body => body, :headers => { :whatever => "Whatever"}) |
10 | | - expect(client.parse_response(response).to_h).to eq({ :body => body, :headers => {}}) |
| 9 | + response = OpenStruct.new(status: 422, body: body, headers: { :whatever => "Whatever"}) |
| 10 | + expect(client.parse_response(response).to_h).to eq({ :body => body, :headers => {status: 422}}) |
11 | 11 | end |
12 | 12 | end |
13 | 13 |
|
14 | 14 | context 'with a non-cortex error response' do |
15 | 15 | it 'should return a wrapped response' do |
16 | 16 | body = 'Catastrophic error' |
17 | | - response = OpenStruct.new(:status => 500, :body => body, :headers => { :whatever => "Whatever" }) |
| 17 | + response = OpenStruct.new(status: 500, body: body, headers: { whatever: "Whatever", status: 500 } ) |
18 | 18 | parsed = client.parse_response(response) |
19 | | - expect(parsed.error).to eq(body) |
20 | | - expect(parsed.status).to eq(500) |
21 | | - expect(parsed.original).to eq(response) |
| 19 | + expect(parsed.body[:error]).to eq(body) |
| 20 | + expect(parsed.body[:status]).to eq(500) |
| 21 | + expect(parsed.body[:original]).to eq(response) |
| 22 | + expect(parsed.headers[:status]).to eq(500) |
22 | 23 | end |
23 | 24 | end |
24 | 25 |
|
25 | 26 | context 'with a successful response' do |
26 | 27 | it 'should return the parsed body' do |
27 | 28 | body = {:id => 1, title: 'A post'} |
28 | | - response = OpenStruct.new(:status => 200, :body => body, :headers => { :whatever => "Whatever" }) |
29 | | - expect(client.parse_response(response).to_h).to eq({ :body => body, :headers => {}}) |
| 29 | + response = OpenStruct.new(status: 200, body: body, headers: { :whatever => "Whatever" }) |
| 30 | + expect(client.parse_response(response).to_h).to eq({ body: body, headers: {status: 200}}) |
30 | 31 | end |
31 | 32 | end |
32 | 33 | end |
0 commit comments