From d1466fcd23da05b3e5155cb045bfd398b2df603d Mon Sep 17 00:00:00 2001 From: Denis Talakevich Date: Wed, 29 Nov 2023 14:05:25 +0200 Subject: [PATCH] normalize labels in metric matcher --- lib/prometheus_exporter/ext/rspec/metric_matcher.rb | 4 +++- spec/prometheus_exporter/ext/metric/gauge_with_time_spec.rb | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/prometheus_exporter/ext/rspec/metric_matcher.rb b/lib/prometheus_exporter/ext/rspec/metric_matcher.rb index 2532263..e05bd7d 100644 --- a/lib/prometheus_exporter/ext/rspec/metric_matcher.rb +++ b/lib/prometheus_exporter/ext/rspec/metric_matcher.rb @@ -27,7 +27,9 @@ def matches?(actual) return false unless values_match?(metric_class, actual.class) return false unless values_match?(metric_name, actual.name.to_s) - return false if !metric_payload.nil? && !values_match?(metric_payload, actual.to_h) + + 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 diff --git a/spec/prometheus_exporter/ext/metric/gauge_with_time_spec.rb b/spec/prometheus_exporter/ext/metric/gauge_with_time_spec.rb index ca6a4ed..ac12690 100644 --- a/spec/prometheus_exporter/ext/metric/gauge_with_time_spec.rb +++ b/spec/prometheus_exporter/ext/metric/gauge_with_time_spec.rb @@ -76,14 +76,14 @@ before do metric.observe(1, 'foo' => 'bar') sleep 0.2 - metric.observe(2, 'baz' => 'boo') + metric.observe(2, baz: 'boo') end it 'has correct to_h' do expect(metric.to_h).to match( { { 'foo' => 'bar' } => [1, ms_since_epoch], - { 'baz' => 'boo' } => [2, ms_since_epoch] + { baz: 'boo' } => [2, ms_since_epoch] } ) end