|
13 | 13 | InformationalResponse = Sus::Shared("informational response") do
|
14 | 14 | it "should be informational" do
|
15 | 15 | expect(response).to be(:informational?)
|
| 16 | + expect(response.as_json).to have_keys(status: be_within(100...200)) |
16 | 17 | end
|
17 | 18 |
|
18 | 19 | it "should not be a failure" do
|
|
23 | 24 | SuccessfulResponse = Sus::Shared("successful response") do
|
24 | 25 | it "should be successful" do
|
25 | 26 | expect(response).to be(:success?)
|
| 27 | + expect(response.as_json).to have_keys(status: be_within(200...300)) |
26 | 28 | end
|
27 | 29 |
|
28 | 30 | it "should be final" do
|
|
45 | 47 |
|
46 | 48 | it "should be a redirection" do
|
47 | 49 | expect(response).to be(:redirection?)
|
| 50 | + expect(response.as_json).to have_keys(status: be_within(300...400)) |
48 | 51 | end
|
49 | 52 |
|
50 | 53 | it "should not be informational" do
|
|
71 | 74 |
|
72 | 75 | it "should be a failure" do
|
73 | 76 | expect(response).to be(:failure?)
|
| 77 | + expect(response.as_json).to have_keys(status: be_within(400...600)) |
74 | 78 | end
|
75 | 79 | end
|
76 | 80 |
|
|
99 | 103 | )
|
100 | 104 | end
|
101 | 105 |
|
| 106 | + with "#as_json" do |
| 107 | + it "generates a JSON representation" do |
| 108 | + expect(response.as_json).to have_keys( |
| 109 | + version: be == "HTTP/1.1", |
| 110 | + status: be == 100, |
| 111 | + headers: be == headers.as_json, |
| 112 | + body: be == nil, |
| 113 | + protocol: be == nil, |
| 114 | + ) |
| 115 | + end |
| 116 | + end |
| 117 | + |
102 | 118 | it_behaves_like InformationalResponse
|
103 | 119 |
|
104 | 120 | it "should be a continue" do
|
|
143 | 159 | end
|
144 | 160 |
|
145 | 161 | with "200 OK" do
|
| 162 | + let(:body) {Protocol::HTTP::Body::Buffered.wrap("Hello, World!")} |
146 | 163 | let(:response) {subject.new("HTTP/1.0", 200, headers, body)}
|
147 | 164 |
|
148 | 165 | it "should have attributes" do
|
|
155 | 172 | )
|
156 | 173 | end
|
157 | 174 |
|
| 175 | + with "#as_json" do |
| 176 | + it "generates a JSON representation" do |
| 177 | + expect(response.as_json).to have_keys( |
| 178 | + version: be == "HTTP/1.0", |
| 179 | + status: be == 200, |
| 180 | + headers: be == headers.as_json, |
| 181 | + body: be == body.as_json, |
| 182 | + protocol: be == nil, |
| 183 | + ) |
| 184 | + end |
| 185 | + end |
| 186 | + |
158 | 187 | it_behaves_like SuccessfulResponse
|
159 | 188 |
|
160 | 189 | it "should be ok" do
|
|
0 commit comments