Class: OpenapiFirst::Test::Coverage::HtmlReporter::Context
- Inherits:
-
Object
- Object
- OpenapiFirst::Test::Coverage::HtmlReporter::Context
- Defined in:
- lib/openapi_first/test/coverage/html_reporter/context.rb
Overview
Provides the binding and helper methods for the ERB template.
Constant Summary collapse
- NO_REQUESTS_WARNING =
'API Coverage did not detect any API requests for the registered ' \ 'API descriptions. Make sure to observe your application using OpenapiFirst::Test.'
Instance Attribute Summary collapse
-
#coverage ⇒ Object
readonly
Returns the value of attribute coverage.
-
#plans ⇒ Object
readonly
Returns the value of attribute plans.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Instance Method Summary collapse
- #any_request_made?(route) ⇒ Boolean
- #expand_plan?(plan) ⇒ Boolean
- #explain_unfinished_request(request) ⇒ Object
- #explain_unfinished_response(response, request_made: false) ⇒ Object
-
#get_binding ⇒ Object
Helper for ERB rendering only — exposes this context’s binding so the template can resolve helper methods and instance state.
- #h(text) ⇒ Object
-
#initialize(coverage_result, verbose) ⇒ Context
constructor
A new instance of Context.
- #request_items(route, plan_verbose:) ⇒ Object
- #response_items(route, plan_verbose:) ⇒ Object
- #route_status(route) ⇒ Object
- #uncovered_responses_count(route) ⇒ Object
- #visible_routes(plan) ⇒ Object
Constructor Details
#initialize(coverage_result, verbose) ⇒ Context
Returns a new instance of Context.
17 18 19 20 21 |
# File 'lib/openapi_first/test/coverage/html_reporter/context.rb', line 17 def initialize(coverage_result, verbose) @coverage = coverage_result.coverage @plans = coverage_result.plans @verbose = verbose end |
Instance Attribute Details
#coverage ⇒ Object (readonly)
Returns the value of attribute coverage.
15 16 17 |
# File 'lib/openapi_first/test/coverage/html_reporter/context.rb', line 15 def coverage @coverage end |
#plans ⇒ Object (readonly)
Returns the value of attribute plans.
15 16 17 |
# File 'lib/openapi_first/test/coverage/html_reporter/context.rb', line 15 def plans @plans end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
15 16 17 |
# File 'lib/openapi_first/test/coverage/html_reporter/context.rb', line 15 def verbose @verbose end |
Instance Method Details
#any_request_made?(route) ⇒ Boolean
39 40 41 |
# File 'lib/openapi_first/test/coverage/html_reporter/context.rb', line 39 def any_request_made?(route) route.requests.any?(&:requested?) end |
#expand_plan?(plan) ⇒ Boolean
29 30 31 |
# File 'lib/openapi_first/test/coverage/html_reporter/context.rb', line 29 def (plan) verbose || plan.done? end |
#explain_unfinished_request(request) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/openapi_first/test/coverage/html_reporter/context.rb', line 71 def explain_unfinished_request(request) return 'No requests tracked!' unless request.requested? return if request.any_valid_request? "All requests invalid! (#{request..inspect})" end |
#explain_unfinished_response(response, request_made: false) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/openapi_first/test/coverage/html_reporter/context.rb', line 78 def explain_unfinished_response(response, request_made: false) unless response.responded? return request_made ? 'No matching response tracked!' : 'No responses tracked!' end "All responses invalid! (#{response..inspect})" unless response.any_valid_response? end |
#get_binding ⇒ Object
Helper for ERB rendering only — exposes this context’s binding so the template can resolve helper methods and instance state.
25 26 27 |
# File 'lib/openapi_first/test/coverage/html_reporter/context.rb', line 25 def get_binding # rubocop:disable Naming/AccessorMethodName binding end |
#h(text) ⇒ Object
67 68 69 |
# File 'lib/openapi_first/test/coverage/html_reporter/context.rb', line 67 def h(text) ERB::Util.html_escape(text) end |
#request_items(route, plan_verbose:) ⇒ Object
54 55 56 57 58 |
# File 'lib/openapi_first/test/coverage/html_reporter/context.rb', line 54 def request_items(route, plan_verbose:) return [] unless any_request_made?(route) && route.requests.any?(&:content_type) plan_verbose ? route.requests : route.requests.reject(&:finished?) end |
#response_items(route, plan_verbose:) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/openapi_first/test/coverage/html_reporter/context.rb', line 60 def response_items(route, plan_verbose:) return [] unless plan_verbose || any_request_made?(route) return route.responses if plan_verbose || route.responses.any? { |r| !r.finished? } [] end |
#route_status(route) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/openapi_first/test/coverage/html_reporter/context.rb', line 43 def route_status(route) return :request_problem if route.requests.none?(&:finished?) return :responses_problem if any_request_made?(route) && route.responses.any? { |r| !r.finished? } :ok end |
#uncovered_responses_count(route) ⇒ Object
50 51 52 |
# File 'lib/openapi_first/test/coverage/html_reporter/context.rb', line 50 def uncovered_responses_count(route) route.responses.count { |r| !r.finished? } end |
#visible_routes(plan) ⇒ Object
33 34 35 36 37 |
# File 'lib/openapi_first/test/coverage/html_reporter/context.rb', line 33 def visible_routes(plan) return plan.routes if (plan) plan.routes.reject(&:finished?) end |