Class: PrometheusExporter::Ext::RSpec::MetricMatcher
- Inherits:
-
Object
- Object
- PrometheusExporter::Ext::RSpec::MetricMatcher
- Includes:
- Matchers, RSpec::Matchers::Composable, RSpec::Matchers::DSL::DefaultImplementations
- Defined in:
- lib/prometheus_exporter/ext/rspec/metric_matcher.rb
Instance Attribute Summary collapse
-
#actual ⇒ Object
readonly
Returns the value of attribute actual.
-
#metric_class ⇒ Object
readonly
Returns the value of attribute metric_class.
-
#metric_name ⇒ Object
readonly
Returns the value of attribute metric_name.
-
#metric_payload ⇒ Object
readonly
Returns the value of attribute metric_payload.
Instance Method Summary collapse
- #description_of(object) ⇒ Object
- #empty ⇒ Object
- #expected ⇒ Object
-
#initialize(metric_class, metric_name) ⇒ MetricMatcher
constructor
A new instance of MetricMatcher.
- #matches?(actual) ⇒ Boolean
- #name ⇒ Object
- #with(value, labels) ⇒ Object
Methods included from Matchers
#a_counter_metric, #a_gauge_metric, #a_gauge_with_expire_metric, #a_histogram_metric, #a_prometheus_metric, #a_summary_metric, #send_metrics
Constructor Details
#initialize(metric_class, metric_name) ⇒ MetricMatcher
Returns a new instance of MetricMatcher.
11 12 13 14 15 |
# File 'lib/prometheus_exporter/ext/rspec/metric_matcher.rb', line 11 def initialize(metric_class, metric_name) @metric_class = metric_class @metric_name = metric_name.to_s @metric_payload = nil end |
Instance Attribute Details
#actual ⇒ Object (readonly)
Returns the value of attribute actual.
9 10 11 |
# File 'lib/prometheus_exporter/ext/rspec/metric_matcher.rb', line 9 def actual @actual end |
#metric_class ⇒ Object (readonly)
Returns the value of attribute metric_class.
9 10 11 |
# File 'lib/prometheus_exporter/ext/rspec/metric_matcher.rb', line 9 def metric_class @metric_class end |
#metric_name ⇒ Object (readonly)
Returns the value of attribute metric_name.
9 10 11 |
# File 'lib/prometheus_exporter/ext/rspec/metric_matcher.rb', line 9 def metric_name @metric_name end |
#metric_payload ⇒ Object (readonly)
Returns the value of attribute metric_payload.
9 10 11 |
# File 'lib/prometheus_exporter/ext/rspec/metric_matcher.rb', line 9 def metric_payload @metric_payload end |
Instance Method Details
#description_of(object) ⇒ Object
48 49 50 |
# File 'lib/prometheus_exporter/ext/rspec/metric_matcher.rb', line 48 def description_of(object) RSpec::Support::ObjectFormatter.new(nil).format(object) end |
#empty ⇒ Object
43 44 45 46 |
# File 'lib/prometheus_exporter/ext/rspec/metric_matcher.rb', line 43 def empty @metric_payload = {} self end |
#expected ⇒ Object
21 22 23 |
# File 'lib/prometheus_exporter/ext/rspec/metric_matcher.rb', line 21 def expected "#{metric_class}(name=#{metric_name}, to_h=#{description_of(metric_payload)})" end |
#matches?(actual) ⇒ Boolean
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/prometheus_exporter/ext/rspec/metric_matcher.rb', line 25 def matches?(actual) @actual = actual return false unless values_match?(metric_class, actual.class) return false unless values_match?(metric_name, actual.name.to_s) actual_payload = actual.to_h.transform_keys { |labels| labels.transform_keys(&:to_s) } return false if !metric_payload.nil? && !values_match?(metric_payload, actual_payload) true end |
#name ⇒ Object
17 18 19 |
# File 'lib/prometheus_exporter/ext/rspec/metric_matcher.rb', line 17 def name 'be a prometheus metric' end |
#with(value, labels) ⇒ Object
37 38 39 40 41 |
# File 'lib/prometheus_exporter/ext/rspec/metric_matcher.rb', line 37 def with(value, labels) @metric_payload ||= {} metric_payload[labels.transform_keys(&:to_s)] = value self end |