|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'spec_helper' |
| 4 | + |
| 5 | +describe 'Errors' do |
| 6 | + describe 'Empty model error' do |
| 7 | + let!(:app) do |
| 8 | + Class.new(Grape::API) do |
| 9 | + format :json |
| 10 | + |
| 11 | + desc 'Empty model get.' do |
| 12 | + http_codes [ |
| 13 | + { code: 200, message: 'get Empty model', model: EmptyClass } |
| 14 | + ] |
| 15 | + end |
| 16 | + get '/empty_model' do |
| 17 | + something = OpenStruct.new text: 'something' |
| 18 | + present something, with: EmptyClass |
| 19 | + end |
| 20 | + |
| 21 | + version 'v3', using: :path |
| 22 | + add_swagger_documentation openapi_version: '3.0', |
| 23 | + api_version: 'v1', |
| 24 | + base_path: '/api', |
| 25 | + info: { |
| 26 | + title: 'The API title to be displayed on the API homepage.', |
| 27 | + description: 'A description of the API.', |
| 28 | + contact_name: 'Contact name', |
| 29 | + contact_email: '[email protected]', |
| 30 | + contact_url: 'Contact URL', |
| 31 | + license: 'The name of the license.', |
| 32 | + license_url: 'www.The-URL-of-the-license.org', |
| 33 | + terms_of_service_url: 'www.The-URL-of-the-terms-and-service.com' |
| 34 | + } |
| 35 | + end |
| 36 | + end |
| 37 | + |
| 38 | + it 'should raise SwaggerSpec exception' do |
| 39 | + expect { get '/v3/swagger_doc' }.to raise_error(GrapeSwagger::Errors::SwaggerSpec, "Empty model EmptyClass, openapi 3.0 doesn't support empty definitions.") |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + describe 'Parser not found error' do |
| 44 | + let!(:app) do |
| 45 | + Class.new(Grape::API) do |
| 46 | + format :json |
| 47 | + |
| 48 | + desc 'Wrong model get.' do |
| 49 | + http_codes [ |
| 50 | + { code: 200, message: 'get Wrong model', model: Hash } |
| 51 | + ] |
| 52 | + end |
| 53 | + get '/wrong_model' do |
| 54 | + something = OpenStruct.new text: 'something' |
| 55 | + present something, with: Hash |
| 56 | + end |
| 57 | + |
| 58 | + version 'v3', using: :path |
| 59 | + add_swagger_documentation openapi_version: '3.0', |
| 60 | + api_version: 'v1', |
| 61 | + base_path: '/api', |
| 62 | + info: { |
| 63 | + title: 'The API title to be displayed on the API homepage.', |
| 64 | + description: 'A description of the API.', |
| 65 | + contact_name: 'Contact name', |
| 66 | + contact_email: '[email protected]', |
| 67 | + contact_url: 'Contact URL', |
| 68 | + license: 'The name of the license.', |
| 69 | + license_url: 'www.The-URL-of-the-license.org', |
| 70 | + terms_of_service_url: 'www.The-URL-of-the-terms-and-service.com' |
| 71 | + } |
| 72 | + end |
| 73 | + end |
| 74 | + |
| 75 | + it 'should raise UnregisteredParser exception' do |
| 76 | + expect { get '/v3/swagger_doc' }.to raise_error(GrapeSwagger::Errors::UnregisteredParser, 'No parser registered for Hash.') |
| 77 | + end |
| 78 | + end |
| 79 | +end |
0 commit comments