Class: ReqresRspec::Collector
- Inherits:
-
Object
- Object
- ReqresRspec::Collector
- Defined in:
- lib/reqres_rspec/collector.rb
Constant Summary collapse
- PARAM_IMPORTANCES =
Param importances
%w[required optional]
- PARAM_TYPES =
Param types NOTE: make sure sub-strings go at the end
['Boolean', 'Text', 'Float', 'DateTime', 'Date', 'File', 'UUID', 'Array of Integer', 'Array of String', 'Array', 'Integer', 'String']
- EXCLUDE_PATH_SYMBOLS =
Exclude replacement in symbolized path
%w[limit offset format description]
- EXCLUDE_RESPONSE_HEADER_PATTERNS =
response headers contain many unnecessary information, everything from this list will be stripped
%w[ X-Frame-Options X-XSS-Protection X-Content-Type-Options X-UA-Compatible X-Request-Id X-Runtime ETag Cache-Control ]
- EXCLUDE_REQUEST_HEADER_PATTERNS =
request headers contain many unnecessary information, everything that match items from this list will be stripped
%w[ rack. sinatra.commonlogger sinatra.route ROUTES_ action_dispatch action_controller. REQUEST_METHOD SERVER_NAME SERVER_PORT QUERY_STRING SCRIPT_NAME CONTENT_LENGTH HTTPS HTTP_HOST HTTP_USER_AGENT REMOTE_ADDR PATH_INFO ORIGINAL_FULLPATH ORIGINAL_SCRIPT_NAME HTTP_COOKIE HTTP_ORIGIN RAW_POST_DATA ]
Instance Attribute Summary collapse
-
#records ⇒ Object
Contains spec values read from rspec example, request and response.
Instance Method Summary collapse
-
#collect(spec, request, response) ⇒ Object
collects spec data for further processing.
-
#initialize ⇒ Collector
constructor
A new instance of Collector.
- #prepare_filename_for(metadata) ⇒ Object
-
#sort ⇒ Object
sorts records alphabetically.
Constructor Details
#initialize ⇒ Collector
Returns a new instance of Collector.
57 58 59 |
# File 'lib/reqres_rspec/collector.rb', line 57 def initialize self.records = [] end |
Instance Attribute Details
#records ⇒ Object
Contains spec values read from rspec example, request and response
4 5 6 |
# File 'lib/reqres_rspec/collector.rb', line 4 def records @records end |
Instance Method Details
#collect(spec, request, response) ⇒ Object
collects spec data for further processing
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/reqres_rspec/collector.rb', line 62 def collect(spec, request, response) # TODO: remove boilerplate code return if request.nil? || response.nil? || !defined?(request.env) description = query_parameters = backend_parameters = 'not available' params = [] if request.env && (request_params = request.env['action_dispatch.request.parameters']) if request_params['controller'] && request_params['action'] description = get_action_description(request_params['controller'], request_params['action']) params = get_action_params(request_params['controller'], request_params['action']) query_parameters = request_params.reject { |p| %w[controller action].include? p } backend_parameters = request_params.reject { |p| !%w[controller action].include? p } end end ex_gr = spec.class.example.[:example_group] section = ex_gr[:description] while !ex_gr.nil? do section = ex_gr[:description] ex_gr = ex_gr[:parent_example_group] end self.records << { filename: prepare_filename_for(spec.class.), group: spec.class.[:reqres_section] || section, # Top level example group title: spec.class.[:reqres_title] || spec.class.example.full_description, description: description, params: params, request_path: get_symbolized_path(request), request: { host: request.host, url: request.url, path: request.path, method: request.request_method, query_parameters: query_parameters, backend_parameters: backend_parameters, body: request.body.read, content_length: request.content_length, content_type: request.content_type, headers: read_request_headers(request), accept: (request.accept rescue nil) }, response: { code: response.status, body: response.body, headers: read_response_headers(response) } } end |
#prepare_filename_for(metadata) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/reqres_rspec/collector.rb', line 112 def prepare_filename_for() description = [:description] example_group = if .key?(:example_group) [:example_group] else [:parent_example_group] end if example_group [prepare_filename_for(example_group), description].join('/') else description end.downcase.gsub(/[\W]+/, '_').gsub('__', '_').gsub(/^_|_$/, '') end |
#sort ⇒ Object
sorts records alphabetically
128 129 130 |
# File 'lib/reqres_rspec/collector.rb', line 128 def sort self.records.sort!{ |x,y| x[:request_path] <=> y[:request_path] } end |