|
34 | 34 | end
|
35 | 35 |
|
36 | 36 | context '#rack_triplet' do
|
37 |
| - it 'should return 200 by default' do |
38 |
| - endpoint = Apia::Endpoint.create('ExampleEndpoint') |
39 |
| - response = Apia::Response.new(request, endpoint) |
40 |
| - expect(response.rack_triplet[0]).to eq 200 |
41 |
| - end |
| 37 | + context 'with a JSON response' do |
| 38 | + it 'should return 200 by default' do |
| 39 | + endpoint = Apia::Endpoint.create('ExampleEndpoint') |
| 40 | + response = Apia::Response.new(request, endpoint) |
| 41 | + expect(response.rack_triplet[0]).to eq 200 |
| 42 | + end |
42 | 43 |
|
43 |
| - it 'should return whatever the status is set to' do |
44 |
| - endpoint = Apia::Endpoint.create('ExampleEndpoint') |
45 |
| - response = Apia::Response.new(request, endpoint) |
46 |
| - response.status = 403 |
47 |
| - expect(response.rack_triplet[0]).to eq 403 |
48 |
| - end |
| 44 | + it 'should return whatever the status is set to' do |
| 45 | + endpoint = Apia::Endpoint.create('ExampleEndpoint') |
| 46 | + response = Apia::Response.new(request, endpoint) |
| 47 | + response.status = 403 |
| 48 | + expect(response.rack_triplet[0]).to eq 403 |
| 49 | + end |
49 | 50 |
|
50 |
| - it 'should return the status from the endpoint' do |
51 |
| - endpoint = Apia::Endpoint.create('ExampleEndpoint') |
52 |
| - endpoint.http_status :created |
53 |
| - response = Apia::Response.new(request, endpoint) |
54 |
| - expect(response.rack_triplet[0]).to eq 201 |
55 |
| - end |
| 51 | + it 'should return the status from the endpoint' do |
| 52 | + endpoint = Apia::Endpoint.create('ExampleEndpoint') |
| 53 | + endpoint.http_status :created |
| 54 | + response = Apia::Response.new(request, endpoint) |
| 55 | + expect(response.rack_triplet[0]).to eq 201 |
| 56 | + end |
56 | 57 |
|
57 |
| - it 'should return the headers' do |
58 |
| - endpoint = Apia::Endpoint.create('ExampleEndpoint') |
59 |
| - response = Apia::Response.new(request, endpoint) |
60 |
| - response.add_header 'x-example', 'hello world' |
61 |
| - expect(response.rack_triplet[1]['x-example']).to eq 'hello world' |
62 |
| - end |
| 58 | + it 'should return the headers' do |
| 59 | + endpoint = Apia::Endpoint.create('ExampleEndpoint') |
| 60 | + response = Apia::Response.new(request, endpoint) |
| 61 | + response.add_header 'x-example', 'hello world' |
| 62 | + expect(response.rack_triplet[1]['x-example']).to eq 'hello world' |
| 63 | + end |
63 | 64 |
|
64 |
| - it 'should always provide the content-type as json' do |
65 |
| - endpoint = Apia::Endpoint.create('ExampleEndpoint') |
66 |
| - response = Apia::Response.new(request, endpoint) |
67 |
| - expect(response.rack_triplet[1]['content-type']).to eq 'application/json' |
68 |
| - end |
| 65 | + it 'should always provide the content-type as json' do |
| 66 | + endpoint = Apia::Endpoint.create('ExampleEndpoint') |
| 67 | + response = Apia::Response.new(request, endpoint) |
| 68 | + expect(response.rack_triplet[1]['content-type']).to eq 'application/json' |
| 69 | + end |
69 | 70 |
|
70 |
| - it 'should always set a content-length' do |
71 |
| - endpoint = Apia::Endpoint.create('ExampleEndpoint') |
72 |
| - response = Apia::Response.new(request, endpoint) |
73 |
| - expect(response.rack_triplet[2][0]).to eq '{}' |
74 |
| - expect(response.rack_triplet[1]['content-length']).to eq '2' |
| 71 | + it 'should always set a content-length' do |
| 72 | + endpoint = Apia::Endpoint.create('ExampleEndpoint') |
| 73 | + response = Apia::Response.new(request, endpoint) |
| 74 | + expect(response.rack_triplet[2][0]).to eq '{}' |
| 75 | + expect(response.rack_triplet[1]['content-length']).to eq '2' |
| 76 | + end |
| 77 | + |
| 78 | + it 'should return the body if one has been set' do |
| 79 | + endpoint = Apia::Endpoint.create('ExampleEndpoint') |
| 80 | + response = Apia::Response.new(request, endpoint) |
| 81 | + response.body = { hello: 'world' } |
| 82 | + expect(response.rack_triplet[2][0]).to eq '{"hello":"world"}' |
| 83 | + expect(response.rack_triplet[1]['content-length']).to eq '17' |
| 84 | + end |
75 | 85 | end
|
76 | 86 |
|
77 |
| - it 'should return the body if one has been set' do |
78 |
| - endpoint = Apia::Endpoint.create('ExampleEndpoint') |
79 |
| - response = Apia::Response.new(request, endpoint) |
80 |
| - response.body = { hello: 'world' } |
81 |
| - expect(response.rack_triplet[2][0]).to eq '{"hello":"world"}' |
82 |
| - expect(response.rack_triplet[1]['content-length']).to eq '17' |
| 87 | + context 'with a plain text response' do |
| 88 | + it 'should return 200 by default' do |
| 89 | + endpoint = Apia::Endpoint.create('ExampleEndpoint') |
| 90 | + response = Apia::Response.new(request, endpoint) |
| 91 | + response.plain! |
| 92 | + expect(response.rack_triplet[0]).to eq 200 |
| 93 | + end |
| 94 | + |
| 95 | + it 'should return whatever the status is set to' do |
| 96 | + endpoint = Apia::Endpoint.create('ExampleEndpoint') |
| 97 | + response = Apia::Response.new(request, endpoint) |
| 98 | + response.plain! |
| 99 | + response.status = 403 |
| 100 | + expect(response.rack_triplet[0]).to eq 403 |
| 101 | + end |
| 102 | + |
| 103 | + it 'should return the status from the endpoint' do |
| 104 | + endpoint = Apia::Endpoint.create('ExampleEndpoint') |
| 105 | + endpoint.http_status :created |
| 106 | + response = Apia::Response.new(request, endpoint) |
| 107 | + response.plain! |
| 108 | + expect(response.rack_triplet[0]).to eq 201 |
| 109 | + end |
| 110 | + |
| 111 | + it 'should return the headers' do |
| 112 | + endpoint = Apia::Endpoint.create('ExampleEndpoint') |
| 113 | + response = Apia::Response.new(request, endpoint) |
| 114 | + response.plain! |
| 115 | + response.add_header 'x-example', 'hello world' |
| 116 | + expect(response.rack_triplet[1]['x-example']).to eq 'hello world' |
| 117 | + end |
| 118 | + |
| 119 | + it 'should always provide the content-type as plain' do |
| 120 | + endpoint = Apia::Endpoint.create('ExampleEndpoint') |
| 121 | + response = Apia::Response.new(request, endpoint) |
| 122 | + response.plain! |
| 123 | + expect(response.rack_triplet[1]['content-type']).to eq 'text/plain' |
| 124 | + end |
| 125 | + |
| 126 | + it 'should always set a content-length' do |
| 127 | + endpoint = Apia::Endpoint.create('ExampleEndpoint') |
| 128 | + response = Apia::Response.new(request, endpoint) |
| 129 | + response.plain! |
| 130 | + expect(response.rack_triplet[2][0]).to eq '' |
| 131 | + expect(response.rack_triplet[1]['content-length']).to eq '0' |
| 132 | + end |
| 133 | + |
| 134 | + it 'should return the body if one has been set' do |
| 135 | + endpoint = Apia::Endpoint.create('ExampleEndpoint') |
| 136 | + response = Apia::Response.new(request, endpoint) |
| 137 | + response.plain! |
| 138 | + response.body = 'hello world' |
| 139 | + expect(response.rack_triplet[2][0]).to eq 'hello world' |
| 140 | + expect(response.rack_triplet[1]['content-length']).to eq '11' |
| 141 | + end |
83 | 142 | end
|
84 | 143 | end
|
85 | 144 | end
|
0 commit comments