grape-swagger/spec/swagger_v2/api_swagger_v2_detail_spec.rb

80 lines
2.2 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2015-12-19 03:29:48 +08:00
require 'spec_helper'
def details
2016-05-07 03:00:36 +08:00
<<-DETAILS
# Burgers in Heaven
2015-12-19 03:29:48 +08:00
> A burger doesn't come for free
2015-12-19 03:29:48 +08:00
If you want to reserve a burger in heaven, you have to do
some crazy stuff on earth.
2015-12-19 03:29:48 +08:00
```
def do_good
puts 'help people'
end
```
2015-12-19 03:29:48 +08:00
* _Will go to Heaven:_ Probably
* _Will go to Hell:_ Probably not
DETAILS
2015-12-19 03:29:48 +08:00
end
describe 'details' do
describe 'take details as it is' do
include_context "#{MODEL_PARSER} swagger example"
2015-12-19 03:29:48 +08:00
before :all do
module TheApi
class DetailApi < Grape::API
format :json
desc 'This returns something',
2016-05-07 03:00:36 +08:00
detail: 'detailed description of the route',
entity: Entities::UseResponse,
failure: [{ code: 400, model: Entities::ApiError }]
2015-12-19 03:29:48 +08:00
get '/use_detail' do
2016-05-07 03:00:36 +08:00
{ 'declared_params' => declared(params) }
2015-12-19 03:29:48 +08:00
end
desc 'This returns something' do
detail 'detailed description of the route inside the `desc` block'
entity Entities::UseResponse
2016-05-07 03:00:36 +08:00
failure [{ code: 400, model: Entities::ApiError }]
2015-12-19 03:29:48 +08:00
end
get '/use_detail_block' do
2016-05-07 03:00:36 +08:00
{ 'declared_params' => declared(params) }
2015-12-19 03:29:48 +08:00
end
add_swagger_documentation
2015-12-19 03:29:48 +08:00
end
end
end
def app
TheApi::DetailApi
end
subject do
get '/swagger_doc'
JSON.parse(last_response.body)
end
specify do
expect(subject['paths']['/use_detail']['get']).to include('summary')
expect(subject['paths']['/use_detail']['get']['summary']).to eql 'This returns something'
2015-12-19 03:29:48 +08:00
expect(subject['paths']['/use_detail']['get']).to include('description')
expect(subject['paths']['/use_detail']['get']['description']).to eql 'detailed description of the route'
2015-12-19 03:29:48 +08:00
end
specify do
expect(subject['paths']['/use_detail_block']['get']).to include('summary')
expect(subject['paths']['/use_detail_block']['get']['summary']).to eql 'This returns something'
2015-12-19 03:29:48 +08:00
expect(subject['paths']['/use_detail_block']['get']).to include('description')
expect(subject['paths']['/use_detail_block']['get']['description']).to eql 'detailed description of the route inside the `desc` block'
2015-12-19 03:29:48 +08:00
end
end
end