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

expect_gitlab_tracking_spec.rb « rspec « cop « rubocop « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d1ce8d01e0bc739ef5e675859f27551da1f413b7 (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
# frozen_string_literal: true

require 'fast_spec_helper'
require 'rubocop'
require_relative '../../../../rubocop/cop/rspec/expect_gitlab_tracking'

RSpec.describe RuboCop::Cop::RSpec::ExpectGitlabTracking do
  let(:source_file) { 'spec/foo_spec.rb' }

  subject(:cop) { described_class.new }

  good_samples = [
    'expect_snowplow_event(category: nil, action: nil)',
    'expect_snowplow_event(category: "EventCategory", action: "event_action")',
    'expect_snowplow_event(category: "EventCategory", action: "event_action", label: "label", property: "property")',
    'expect_no_snowplow_event'
  ]

  bad_samples = [
    'expect(Gitlab::Tracking).to receive(:event)',
    'expect(Gitlab::Tracking).to_not receive(:event)',
    'expect(Gitlab::Tracking).not_to receive(:event)',
    'expect(Gitlab::Tracking).to_not receive(:event).with("EventCategory", "event_action")',
    'expect(Gitlab::Tracking).not_to receive(:event).with("EventCategory", "event_action")',
    'expect(Gitlab::Tracking).to receive(:event).with("EventCategory", "event_action", label: "label", property: "property")',
    'expect(Gitlab::Tracking).to have_received(:event).with("EventCategory", "event_action")',
    'expect(Gitlab::Tracking).to_not have_received(:event).with("EventCategory", "event_action")',
    'expect(Gitlab::Tracking).not_to have_received(:event).with("EventCategory", "event_action")',
    'allow(Gitlab::Tracking).to receive(:event).and_call_original'
  ]

  good_samples.each do |good|
    context "good: #{good}" do
      it 'does not register an offense' do
        expect_no_offenses(good)
      end
    end
  end

  bad_samples.each do |bad|
    context "bad: #{bad}" do
      it 'registers an offense' do
        expect_offense(<<~CODE, node: bad)
          %{node}
          ^{node} Do not expect directly on `Gitlab::Tracking#event`[...]
        CODE
      end
    end
  end
end