Commit d762147b authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'nicolasdular/fix-snowplow-spec-helper' into 'master'

Fix Snowplow spec helper for Ruby 2.6.6

See merge request gitlab-org/gitlab!44711
parents bcf0fc72 45ab261f
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe PrometheusService, :use_clean_rails_memory_store_caching do
RSpec.describe PrometheusService, :use_clean_rails_memory_store_caching, :snowplow do
include PrometheusHelpers
include ReactiveCachingHelpers
......@@ -421,18 +421,16 @@ RSpec.describe PrometheusService, :use_clean_rails_memory_store_caching do
context "enabling manual_configuration" do
it "tracks enable event" do
service.update!(manual_configuration: false)
expect(Gitlab::Tracking).to receive(:event).with('cluster:services:prometheus', 'enabled_manual_prometheus')
service.update!(manual_configuration: true)
expect_snowplow_event(category: 'cluster:services:prometheus', action: 'enabled_manual_prometheus')
end
it "tracks disable event" do
service.update!(manual_configuration: true)
expect(Gitlab::Tracking).to receive(:event).with('cluster:services:prometheus', 'disabled_manual_prometheus')
service.update!(manual_configuration: false)
expect_snowplow_event(category: 'cluster:services:prometheus', action: 'disabled_manual_prometheus')
end
end
end
......
......@@ -32,8 +32,16 @@ module SnowplowHelpers
# end
# end
def expect_snowplow_event(category:, action:, **kwargs)
expect(Gitlab::Tracking).to have_received(:event)
.with(category, action, **kwargs).at_least(:once)
# This check will no longer be needed with Ruby 2.7 which
# would not pass any arguments when using **kwargs.
# https://gitlab.com/gitlab-org/gitlab/-/issues/263430
if kwargs.present?
expect(Gitlab::Tracking).to have_received(:event)
.with(category, action, **kwargs).at_least(:once)
else
expect(Gitlab::Tracking).to have_received(:event)
.with(category, action).at_least(:once)
end
end
# Asserts that no call to `Gitlab::Tracking#event` was made.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment