diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d7df1264fe31c7580ac622ef0b269ad07126afc9..19115b7bedbacdf1eba8caaaa05775b74dac4828 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -186,31 +186,21 @@ RSpec/ExpectChange: # Offense count: 47 RSpec/ExpectGitlabTracking: Exclude: - - 'ee/spec/controllers/groups/analytics/coverage_reports_controller_spec.rb' - 'ee/spec/controllers/projects/settings/operations_controller_spec.rb' - - 'ee/spec/controllers/registrations_controller_spec.rb' - 'ee/spec/requests/api/visual_review_discussions_spec.rb' - 'ee/spec/services/epics/issue_promote_service_spec.rb' - 'spec/controllers/groups/registry/repositories_controller_spec.rb' - - 'spec/controllers/groups_controller_spec.rb' - 'spec/controllers/projects/registry/repositories_controller_spec.rb' - 'spec/controllers/projects/registry/tags_controller_spec.rb' - 'spec/controllers/projects/settings/operations_controller_spec.rb' - 'spec/controllers/registrations_controller_spec.rb' - 'spec/lib/api/helpers_spec.rb' - - 'spec/lib/gitlab/experimentation_spec.rb' - - 'spec/mailers/notify_spec.rb' - - 'spec/models/project_services/prometheus_service_spec.rb' - 'spec/requests/api/project_container_repositories_spec.rb' - - 'spec/services/clusters/applications/check_installation_progress_service_spec.rb' - - 'spec/services/issues/zoom_link_service_spec.rb' - - 'spec/support/helpers/snowplow_helpers.rb' - 'spec/support/shared_examples/controllers/trackable_shared_examples.rb' - 'spec/support/shared_examples/requests/api/container_repositories_shared_examples.rb' - 'spec/support/shared_examples/requests/api/discussions_shared_examples.rb' - 'spec/support/shared_examples/requests/api/packages_shared_examples.rb' - 'spec/support/shared_examples/requests/api/tracking_shared_examples.rb' - - 'spec/support/snowplow.rb' # Offense count: 751 RSpec/ExpectInHook: diff --git a/ee/spec/controllers/groups/analytics/coverage_reports_controller_spec.rb b/ee/spec/controllers/groups/analytics/coverage_reports_controller_spec.rb index 79775a63c4bb343a30d8a5af4002749608e097c1..452c75f4cdac51387193ec8648fc13fb8396a1f2 100644 --- a/ee/spec/controllers/groups/analytics/coverage_reports_controller_spec.rb +++ b/ee/spec/controllers/groups/analytics/coverage_reports_controller_spec.rb @@ -59,16 +59,16 @@ stub_licensed_features(group_coverage_reports: true) end - it 'responds 200 with CSV coverage data' do - expect(Gitlab::Tracking).to receive(:event).with( - described_class.name, - 'download_code_coverage_csv', + it 'responds 200 with CSV coverage data', :snowplow do + get :index, params: valid_request_params + + expect_snowplow_event( + category: described_class.name, + action: 'download_code_coverage_csv', label: 'group_id', value: group.id ) - get :index, params: valid_request_params - expect(response).to have_gitlab_http_status(:ok) expect(csv_response).to eq([ %w[date group_name project_name coverage], diff --git a/ee/spec/controllers/registrations_controller_spec.rb b/ee/spec/controllers/registrations_controller_spec.rb index 8e8a00bc9de5da586cc6793308320f529215bed1..150071aa72f6d81258ce6c9bba675654f4f6252d 100644 --- a/ee/spec/controllers/registrations_controller_spec.rb +++ b/ee/spec/controllers/registrations_controller_spec.rb @@ -148,15 +148,15 @@ update_registration end - it 'tracks a signed_up event' do - expect(Gitlab::Tracking).to receive(:event).with( - 'Growth::Conversion::Experiment::OnboardingIssues', - 'signed_up', + it 'tracks a signed_up event', :snowplow do + update_registration + + expect_snowplow_event( + category: 'Growth::Conversion::Experiment::OnboardingIssues', + action: 'signed_up', label: anything, property: "#{group_type}_group" ) - - update_registration end end end @@ -176,10 +176,10 @@ update_registration end - it 'does not track a signed_up event' do - expect(Gitlab::Tracking).not_to receive(:event) - + it 'does not track a signed_up event', :snowplow do update_registration + + expect_no_snowplow_event end end end @@ -196,10 +196,10 @@ update_registration end - it 'does not track a signed_up event' do - expect(Gitlab::Tracking).not_to receive(:event) - + it 'does not track a signed_up event', :snowplow do update_registration + + expect_no_snowplow_event end end end diff --git a/ee/spec/requests/api/visual_review_discussions_spec.rb b/ee/spec/requests/api/visual_review_discussions_spec.rb index 8b17d5993855c9b61c3f18d56f9c6a99d7b512d4..34f3a3c4c9b9891bd9890c00500c5e7c67d050f6 100644 --- a/ee/spec/requests/api/visual_review_discussions_spec.rb +++ b/ee/spec/requests/api/visual_review_discussions_spec.rb @@ -58,9 +58,10 @@ stub_feature_flags(notes_create_service_tracking: false) end - it 'does not track any events' do - expect(Gitlab::Tracking).not_to receive(:event) + it 'does not track any events', :snowplow do request + + expect_no_snowplow_event end end diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index d92dae6fc5a22eec23015b0d0dad18df08bf2940..55833ee3aadc611a7cba629513e5f00f3c6e9241 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -319,10 +319,10 @@ stub_experiment(onboarding_issues: false) end - it 'does not track anything' do - expect(Gitlab::Tracking).not_to receive(:event) - + it 'does not track anything', :snowplow do create_namespace + + expect_no_snowplow_event end end @@ -336,15 +336,15 @@ stub_experiment_for_user(onboarding_issues: false) end - it 'tracks the event with the "created_namespace" action with the "control_group" property' do - expect(Gitlab::Tracking).to receive(:event).with( - 'Growth::Conversion::Experiment::OnboardingIssues', - 'created_namespace', + it 'tracks the event with the "created_namespace" action with the "control_group" property', :snowplow do + create_namespace + + expect_snowplow_event( + category: 'Growth::Conversion::Experiment::OnboardingIssues', + action: 'created_namespace', label: anything, property: 'control_group' ) - - create_namespace end end @@ -353,15 +353,15 @@ stub_experiment_for_user(onboarding_issues: true) end - it 'tracks the event with the "created_namespace" action with the "experimental_group" property' do - expect(Gitlab::Tracking).to receive(:event).with( - 'Growth::Conversion::Experiment::OnboardingIssues', - 'created_namespace', + it 'tracks the event with the "created_namespace" action with the "experimental_group" property', :snowplow do + create_namespace + + expect_snowplow_event( + category: 'Growth::Conversion::Experiment::OnboardingIssues', + action: 'created_namespace', label: anything, property: 'experimental_group' ) - - create_namespace end end end diff --git a/spec/services/clusters/applications/check_installation_progress_service_spec.rb b/spec/services/clusters/applications/check_installation_progress_service_spec.rb index 13f7cd620028a4ee0e2a54711974a7f5f50f23f9..698804ff6af86e77b8bcf90c3c9f6574cdf1580f 100644 --- a/spec/services/clusters/applications/check_installation_progress_service_spec.rb +++ b/spec/services/clusters/applications/check_installation_progress_service_spec.rb @@ -161,10 +161,10 @@ expect(application.status_reason).to be_nil end - it 'tracks application install' do - expect(Gitlab::Tracking).to receive(:event).with('cluster:applications', "cluster_application_helm_installed") - + it 'tracks application install', :snowplow do service.execute + + expect_snowplow_event(category: 'cluster:applications', action: 'cluster_application_helm_installed') end end diff --git a/spec/services/issues/zoom_link_service_spec.rb b/spec/services/issues/zoom_link_service_spec.rb index b095cb2421216f8fcaf7266877c90d43c905ef90..8e8adc516cfbc5fffe5257d1d04fdb9c28dee2a3 100644 --- a/spec/services/issues/zoom_link_service_spec.rb +++ b/spec/services/issues/zoom_link_service_spec.rb @@ -46,10 +46,15 @@ expect(ZoomMeeting.canonical_meeting_url(issue)).to eq(zoom_link) end - it 'tracks the add event' do - expect(Gitlab::Tracking).to receive(:event) - .with('IncidentManagement::ZoomIntegration', 'add_zoom_meeting', label: 'Issue ID', value: issue.id) + it 'tracks the add event', :snowplow do result + + expect_snowplow_event( + category: 'IncidentManagement::ZoomIntegration', + action: 'add_zoom_meeting', + label: 'Issue ID', + value: issue.id + ) end it 'creates a zoom_link_added notification' do @@ -180,10 +185,15 @@ expect(ZoomMeeting.canonical_meeting_url(issue)).to eq(nil) end - it 'tracks the remove event' do - expect(Gitlab::Tracking).to receive(:event) - .with('IncidentManagement::ZoomIntegration', 'remove_zoom_meeting', label: 'Issue ID', value: issue.id) + it 'tracks the remove event', :snowplow do result + + expect_snowplow_event( + category: 'IncidentManagement::ZoomIntegration', + action: 'remove_zoom_meeting', + label: 'Issue ID', + value: issue.id + ) end end diff --git a/spec/support/helpers/snowplow_helpers.rb b/spec/support/helpers/snowplow_helpers.rb index 3bde01c6fbfa4f25a45343a37ee6aaa215ded321..0c6d2bfad633375dfb3f268f7502751575a3d488 100644 --- a/spec/support/helpers/snowplow_helpers.rb +++ b/spec/support/helpers/snowplow_helpers.rb @@ -36,10 +36,10 @@ def expect_snowplow_event(category:, action:, **kwargs) # 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) + expect(Gitlab::Tracking).to have_received(:event) # rubocop:disable RSpec/ExpectGitlabTracking .with(category, action, **kwargs).at_least(:once) else - expect(Gitlab::Tracking).to have_received(:event) + expect(Gitlab::Tracking).to have_received(:event) # rubocop:disable RSpec/ExpectGitlabTracking .with(category, action).at_least(:once) end end @@ -56,6 +56,6 @@ def expect_snowplow_event(category:, action:, **kwargs) # end # end def expect_no_snowplow_event - expect(Gitlab::Tracking).not_to have_received(:event) + expect(Gitlab::Tracking).not_to have_received(:event) # rubocop:disable RSpec/ExpectGitlabTracking end end diff --git a/spec/support/snowplow.rb b/spec/support/snowplow.rb index 58812b8f4e69573c45610778eb990d0ad6507e13..ae00e30a191166f56b3c01eabe2101b1d4645cd2 100644 --- a/spec/support/snowplow.rb +++ b/spec/support/snowplow.rb @@ -13,7 +13,7 @@ stub_application_setting(snowplow_enabled: true) - allow(Gitlab::Tracking).to receive(:event).and_call_original + allow(Gitlab::Tracking).to receive(:event).and_call_original # rubocop:disable RSpec/ExpectGitlabTracking end config.after(:each, :snowplow) do