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
-
#filepath ⇒ Object
readonly
Returns the value of attribute filepath.
-
#oad ⇒ Object
readonly
Returns the value of attribute oad.
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
- #coverage ⇒ Object
- #done? ⇒ Boolean
-
#initialize(oad) ⇒ Plan
constructor
A new instance of Plan.
- #tasks ⇒ Object
- #track_request(validated_request) ⇒ Object
- #track_response(validated_response) ⇒ Object
Constructor Details
#initialize(oad) ⇒ Plan
Returns a new instance of Plan.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/openapi_first/test/coverage/plan.rb', line 15 def initialize(oad) @oad = oad @routes = [] @index = {} @filepath = oad.filepath oad.routes.each do |route| add_route request_method: route.request_method, path: route.path, requests: route.requests, responses: route.responses end end |
Instance Attribute Details
#filepath ⇒ Object (readonly)
Returns the value of attribute filepath.
28 29 30 |
# File 'lib/openapi_first/test/coverage/plan.rb', line 28 def filepath @filepath end |
#oad ⇒ Object (readonly)
Returns the value of attribute oad.
28 29 30 |
# File 'lib/openapi_first/test/coverage/plan.rb', line 28 def oad @oad end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
28 29 30 |
# File 'lib/openapi_first/test/coverage/plan.rb', line 28 def routes @routes end |
Instance Method Details
#coverage ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/openapi_first/test/coverage/plan.rb', line 43 def coverage done = tasks.count(&:finished?) return 0 if done.zero? all = tasks.count (done / (all.to_f / 100)).to_i end |
#done? ⇒ Boolean
39 40 41 |
# File 'lib/openapi_first/test/coverage/plan.rb', line 39 def done? tasks.all?(&:finished?) end |
#tasks ⇒ Object
51 52 53 |
# File 'lib/openapi_first/test/coverage/plan.rb', line 51 def tasks index.values end |
#track_request(validated_request) ⇒ Object
31 32 33 |
# File 'lib/openapi_first/test/coverage/plan.rb', line 31 def track_request(validated_request) index[validated_request.request_definition.key].track(validated_request) if validated_request.known? end |
#track_response(validated_response) ⇒ Object
35 36 37 |
# File 'lib/openapi_first/test/coverage/plan.rb', line 35 def track_response(validated_response) index[validated_response.response_definition.key].track(validated_response) if validated_response.known? end |