Skip to content

Commit 2498c53

Browse files
committed
Raise ArgumentError when the expected status does not exist
1 parent ae36c9b commit 2498c53

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

lib/openapi_contracts/rspec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929

3030
def with_http_status(status)
3131
if status.is_a? Symbol
32-
@status = Rack::Utils::SYMBOL_TO_STATUS_CODE[status]
32+
@status = Rack::Utils::SYMBOL_TO_STATUS_CODE.fetch(status) do
33+
raise ArgumentError, "Unknown status #{status.inspect}"
34+
end
3335
else
3436
@status = status
3537
end

spec/integration/rspec_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@
9090
it { is_expected.to match_openapi_doc(doc).with_http_status(:bad_request) }
9191
end
9292

93+
context 'when using unsupported status' do
94+
it {
95+
expect {
96+
expect(subject).to match_openapi_doc(doc).with_http_status(:does_not_exist_in_rack)
97+
}.to raise_error(ArgumentError, 'Unknown status :does_not_exist_in_rack')
98+
}
99+
end
100+
93101
context 'when using dynamic paths' do
94102
let(:path) { '/messages/ef278ab2' }
95103
let(:response_json) do

0 commit comments

Comments
 (0)