Commit 70a0d5ff authored by Nicolas Dular's avatar Nicolas Dular

Call snowplow for gitlab-experiment specs

Snowplow checks types at runtime and therefore could lead to failures
when using the wrong type for an event tracking property.
We already call the original method in specs when `:snowplow` tag is
used, but haven't so far for the custom rspec methods from
`gitlab-experiment` gem.
parent 0d347294
......@@ -2,6 +2,7 @@
# Require the provided spec helper and matchers.
require 'gitlab/experiment/rspec'
require_relative 'stub_snowplow'
# This is a temporary fix until we have a larger discussion around the
# challenges raised in https://gitlab.com/gitlab-org/gitlab/-/issues/300104
......@@ -10,11 +11,21 @@ class ApplicationExperiment # rubocop:disable Gitlab/NamespacedClass
super(...)
Feature.persist_used!(feature_flag_name)
end
def should_track?
true
end
end
RSpec.configure do |config|
config.include StubSnowplow, :experiment
# Disable all caching for experiments in tests.
config.before do
allow(Gitlab::Experiment::Configuration).to receive(:cache).and_return(nil)
end
config.before(:each, :experiment) do
stub_snowplow
end
end
# frozen_string_literal: true
require_relative 'stub_snowplow'
RSpec.configure do |config|
config.include SnowplowHelpers, :snowplow
config.include StubSnowplow, :snowplow
config.before(:each, :snowplow) do
# Using a high buffer size to not cause early flushes
buffer_size = 100
# WebMock is set up to allow requests to `localhost`
host = 'localhost'
allow_any_instance_of(Gitlab::Tracking::Destinations::ProductAnalytics).to receive(:event)
allow_any_instance_of(Gitlab::Tracking::Destinations::Snowplow)
.to receive(:emitter)
.and_return(SnowplowTracker::Emitter.new(host, buffer_size: buffer_size))
stub_application_setting(snowplow_enabled: true)
allow(SnowplowTracker::SelfDescribingJson).to receive(:new).and_call_original
allow(Gitlab::Tracking).to receive(:event).and_call_original # rubocop:disable RSpec/ExpectGitlabTracking
stub_snowplow
end
config.after(:each, :snowplow) do
......
# frozen_string_literal: true
module StubSnowplow
def stub_snowplow
# Using a high buffer size to not cause early flushes
buffer_size = 100
# WebMock is set up to allow requests to `localhost`
host = 'localhost'
# rubocop:disable RSpec/AnyInstanceOf
allow_any_instance_of(Gitlab::Tracking::Destinations::ProductAnalytics).to receive(:event)
allow_any_instance_of(Gitlab::Tracking::Destinations::Snowplow)
.to receive(:emitter)
.and_return(SnowplowTracker::Emitter.new(host, buffer_size: buffer_size))
# rubocop:enable RSpec/AnyInstanceOf
stub_application_setting(snowplow_enabled: true)
allow(SnowplowTracker::SelfDescribingJson).to receive(:new).and_call_original
allow(Gitlab::Tracking).to receive(:event).and_call_original # rubocop:disable RSpec/ExpectGitlabTracking
end
end
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