Welcome to mirror list, hosted at ThFree Co, Russian Federation.

snowplow_helpers.rb « helpers « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 15eac1b24fc589bb7cb0ddac2838a8c6f323ee01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# frozen_string_literal: true

module SnowplowHelpers
  # Asserts call for one snowplow event from `Gitlab::Tracking#event`.
  #
  # @param [Hash]
  #
  # Examples:
  #
  #   describe '#show', :snowplow do
  #     it 'tracks snowplow events' do
  #       get :show
  #
  #       expect_snowplow_event(category: 'Experiment', action: 'start')
  #     end
  #   end
  #
  #   describe '#create', :snowplow do
  #     it 'tracks snowplow events' do
  #       post :create
  #
  #       expect_snowplow_event(
  #         category: 'Experiment',
  #         action: 'created',
  #       )
  #       expect_snowplow_event(
  #         category: 'Experiment',
  #         action: 'accepted',
  #         property: 'property',
  #         label: 'label'
  #       )
  #     end
  #   end
  def expect_snowplow_event(category:, action:, **kwargs)
    expect(Gitlab::Tracking).to have_received(:event) # rubocop:disable RSpec/ExpectGitlabTracking
      .with(category, action, **kwargs).at_least(:once)
  end

  # Asserts that no call to `Gitlab::Tracking#event` was made.
  #
  # Example:
  #
  #   describe '#show', :snowplow do
  #     it 'does not track any snowplow events' do
  #       get :show
  #
  #       expect_no_snowplow_event
  #     end
  #   end
  def expect_no_snowplow_event
    expect(Gitlab::Tracking).not_to have_received(:event) # rubocop:disable RSpec/ExpectGitlabTracking
  end
end