Class: OpenapiFirst::Test::Coverage::Plan
- Inherits:
-
Object
- Object
- OpenapiFirst::Test::Coverage::Plan
- Defined in:
- lib/openapi_first/test/coverage/plan.rb
Overview
This stores the coverage data for one API description A plan can be #done? and has several #tasks which can be #finished?
Defined Under Namespace
Classes: UnknownRequestError
Instance Attribute Summary collapse
-
#api_identifier ⇒ Object
readonly
Returns the value of attribute api_identifier.
-
#filepath ⇒ Object
readonly
Returns the value of attribute filepath.
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #add_route(request_method:, path:, requests:, responses:) ⇒ Object
- #coverage ⇒ Object
- #done? ⇒ Boolean
-
#initialize(definition_key:, filepath: nil, title: nil) ⇒ Plan
constructor
A new instance of Plan.
- #tasks ⇒ Object
- #track_request(validated_request) ⇒ Object
- #track_response(validated_response) ⇒ Object
Constructor Details
#initialize(definition_key:, filepath: nil, title: nil) ⇒ Plan
Returns a new instance of Plan.
29 30 31 32 33 34 35 |
# File 'lib/openapi_first/test/coverage/plan.rb', line 29 def initialize(definition_key:, filepath: nil, title: nil) @routes = [] @index = {} @api_identifier = filepath || definition_key @filepath = filepath @title = title end |
Instance Attribute Details
#api_identifier ⇒ Object (readonly)
Returns the value of attribute api_identifier.
37 38 39 |
# File 'lib/openapi_first/test/coverage/plan.rb', line 37 def api_identifier @api_identifier end |
#filepath ⇒ Object (readonly)
Returns the value of attribute filepath.
37 38 39 |
# File 'lib/openapi_first/test/coverage/plan.rb', line 37 def filepath @filepath end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
37 38 39 |
# File 'lib/openapi_first/test/coverage/plan.rb', line 37 def routes @routes end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
37 38 39 |
# File 'lib/openapi_first/test/coverage/plan.rb', line 37 def title @title end |
Class Method Details
.for(oad, skip_response: nil, skip_route: nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/openapi_first/test/coverage/plan.rb', line 15 def self.for(oad, skip_response: nil, skip_route: nil) plan = new(definition_key: oad.key, filepath: oad.filepath, title: oad.title) routes = oad.routes routes = routes.reject { |route| skip_route[route.path, route.request_method] } if skip_route routes.each do |route| responses = skip_response ? route.responses.reject(&skip_response) : route.responses plan.add_route request_method: route.request_method, path: route.path, requests: route.requests, responses: end plan end |
Instance Method Details
#add_route(request_method:, path:, requests:, responses:) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/openapi_first/test/coverage/plan.rb', line 66 def add_route(request_method:, path:, requests:, responses:) request_tasks = requests.to_a.map do |request| index[request.key] = RequestTask.new(request) end response_tasks = responses.to_a.map do |response| index[response.key] = ResponseTask.new(response) end @routes << RouteTask.new(path:, request_method:, requests: request_tasks, responses: response_tasks) end |
#coverage ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/openapi_first/test/coverage/plan.rb', line 52 def coverage done = tasks.count(&:finished?) return 0 if done.zero? all = tasks.count return 100 if done == all (done / (all.to_f / 100)) end |
#done? ⇒ Boolean
48 49 50 |
# File 'lib/openapi_first/test/coverage/plan.rb', line 48 def done? tasks.all?(&:finished?) end |
#tasks ⇒ Object
62 63 64 |
# File 'lib/openapi_first/test/coverage/plan.rb', line 62 def tasks index.values end |
#track_request(validated_request) ⇒ Object
40 41 42 |
# File 'lib/openapi_first/test/coverage/plan.rb', line 40 def track_request(validated_request) index[validated_request.key]&.track(validated_request) end |
#track_response(validated_response) ⇒ Object
44 45 46 |
# File 'lib/openapi_first/test/coverage/plan.rb', line 44 def track_response(validated_response) index[validated_response.key]&.track(validated_response) end |