|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | | -require './lib/error_response' |
| 3 | +require "./lib/error_response" |
4 | 4 |
|
5 | 5 | RSpec.describe ErrorResponse do |
6 | | - describe '#yaml_hash' do |
7 | | - it 'should fetch data from local' do |
| 6 | + describe "#yaml_hash" do |
| 7 | + it "should fetch data from local" do |
8 | 8 | result = ErrorResponse.to_api(:resource_not_found) |
9 | | - expect(result[:json]['error_message']).to eq 'resource not found' |
10 | | - expect(result[:json]['error_code']).to eq 404_001 |
| 9 | + expect(result[:json]["error_message"]).to eq "resource not found" |
| 10 | + expect(result[:json]["error_code"]).to eq 404_001 |
11 | 11 | end |
12 | 12 |
|
13 | | - it 'should fetch data from remote' do |
| 13 | + it "should fetch data from remote" do |
14 | 14 | result = ErrorResponse.to_api(:bad_request_2) |
15 | | - expect(result[:json]['error_message']).to eq 'bad request 2' |
16 | | - expect(result[:json]['error_code']).to eq 400_002 |
| 15 | + expect(result[:json]["error_message"]).to eq "bad request 2" |
| 16 | + expect(result[:json]["error_code"]).to eq 400_002 |
17 | 17 | end |
18 | 18 | end |
19 | 19 |
|
20 | | - describe '#to_api' do |
21 | | - it 'should return correspond hash when key existed' do |
| 20 | + describe "#to_api" do |
| 21 | + it "should return correspond hash when key existed" do |
22 | 22 | hash = { |
23 | 23 | status: 400, |
24 | 24 | json: { |
25 | | - 'error_code' => 400_001, |
26 | | - 'error_message' => 'bad request 1', |
27 | | - 'error_key' => 'bad_request_1' |
| 25 | + "error_code" => 400_001, |
| 26 | + "error_message" => "bad request 1", |
| 27 | + "error_key" => "bad_request_1" |
28 | 28 | } |
29 | 29 | } |
30 | 30 | result = ErrorResponse.to_api(:bad_request_1) |
31 | 31 | expect(result).to eq hash |
32 | 32 | end |
33 | 33 |
|
34 | | - it 'should return personalized hash when key not existed' do |
| 34 | + it "should return personalized hash when key not existed" do |
35 | 35 | hash = { |
36 | 36 | status: 500, |
37 | 37 | json: { |
38 | | - 'error_code' => 500_000, |
39 | | - 'error_message' => 'internal_error: something went wrong', |
40 | | - 'error_key' => 'internal_error' |
| 38 | + "error_code" => 500_000, |
| 39 | + "error_message" => "internal_error: something went wrong", |
| 40 | + "error_key" => "internal_error" |
41 | 41 | } |
42 | 42 | } |
43 | | - result = ErrorResponse.to_api(:internal_error, 'something went wrong') |
| 43 | + result = ErrorResponse.to_api(:internal_error, "something went wrong") |
44 | 44 | expect(result).to eq hash |
45 | 45 | end |
46 | 46 | end |
47 | 47 |
|
48 | | - describe '#to_hash' do |
49 | | - it 'should return hash when key existed' do |
| 48 | + describe "#to_hash" do |
| 49 | + it "should return hash when key existed" do |
50 | 50 | hash = { |
51 | | - 'error_code' => 400_001, |
52 | | - 'error_message' => 'bad request 1', |
53 | | - 'error_key' => 'bad_request_1' |
| 51 | + "error_code" => 400_001, |
| 52 | + "error_message" => "bad request 1", |
| 53 | + "error_key" => "bad_request_1" |
54 | 54 | } |
55 | 55 | result = ErrorResponse.to_hash(:bad_request_1) |
56 | 56 | expect(result).to eq hash |
57 | 57 | end |
58 | 58 |
|
59 | | - it 'should return hash when key existed in remote source' do |
| 59 | + it "should return hash when key existed in remote source" do |
60 | 60 | hash = { |
61 | | - 'error_code' => 400_002, |
62 | | - 'error_message' => 'bad request 2', |
63 | | - 'error_key' => 'bad_request_2' |
| 61 | + "error_code" => 400_002, |
| 62 | + "error_message" => "bad request 2", |
| 63 | + "error_key" => "bad_request_2" |
64 | 64 | } |
65 | 65 | result = ErrorResponse.to_hash(:bad_request_2) |
66 | 66 | expect(result).to eq hash |
67 | 67 | end |
68 | 68 |
|
69 | | - it 'should return {} when key not existed' do |
| 69 | + it "should return {} when key not existed" do |
70 | 70 | result = ErrorResponse.to_hash(:some_error) |
71 | 71 | empty_hash = {} |
72 | 72 | expect(result).to eq empty_hash |
|
0 commit comments