-
Notifications
You must be signed in to change notification settings - Fork 63
/
rack.rb
31 lines (28 loc) · 1.26 KB
/
rack.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true
# Extractor for rack
class << RSpec::OpenAPI::Extractors::Rack = Object.new
# @param [ActionDispatch::Request] request
# @param [RSpec::Core::Example] example
# @return Array
def request_attributes(request, example)
metadata = example.metadata[:openapi] || {}
summary = metadata[:summary] || RSpec::OpenAPI.summary_builder.call(example)
tags = metadata[:tags] || RSpec::OpenAPI.tags_builder.call(example)
operation_id = metadata[:operation_id]
required_request_params = metadata[:required_request_params] || []
security = metadata[:security]
description = metadata[:description] || RSpec::OpenAPI.description_builder.call(example)
deprecated = metadata[:deprecated]
raw_path_params = request.path_parameters
path = request.path
summary ||= "#{request.method} #{path}"
[path, summary, tags, operation_id, required_request_params, raw_path_params, description, security, deprecated]
end
# @param [RSpec::ExampleGroups::*] context
def request_response(context)
request = ActionDispatch::Request.new(context.last_request.env)
request.body.rewind if request.body.respond_to?(:rewind)
response = ActionDispatch::TestResponse.new(*context.last_response.to_a)
[request, response]
end
end