diff --git a/.ruby-version b/.ruby-version index 47b322c..2aa5131 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.4.1 +3.4.7 diff --git a/lib/openapi_contracts/rspec.rb b/lib/openapi_contracts/rspec.rb index b183e10..966ee2b 100644 --- a/lib/openapi_contracts/rspec.rb +++ b/lib/openapi_contracts/rspec.rb @@ -29,7 +29,9 @@ def with_http_status(status) if status.is_a? Symbol - @status = Rack::Utils::SYMBOL_TO_STATUS_CODE[status] + @status = Rack::Utils::SYMBOL_TO_STATUS_CODE.fetch(status) do + raise ArgumentError, "Unknown status #{status.inspect}" + end else @status = status end diff --git a/spec/integration/rspec_spec.rb b/spec/integration/rspec_spec.rb index cd11408..d3464b7 100644 --- a/spec/integration/rspec_spec.rb +++ b/spec/integration/rspec_spec.rb @@ -90,6 +90,14 @@ it { is_expected.to match_openapi_doc(doc).with_http_status(:bad_request) } end + context 'when using unsupported status' do + it { + expect { + expect(subject).to match_openapi_doc(doc).with_http_status(:does_not_exist_in_rack) + }.to raise_error(ArgumentError, 'Unknown status :does_not_exist_in_rack') + } + end + context 'when using dynamic paths' do let(:path) { '/messages/ef278ab2' } let(:response_json) do