summaryrefslogtreecommitdiff
path: root/spec/rubocop/cop/scalability/idempotent_worker_spec.rb
blob: 7abd602f8bc9e4dd015291c278e08024c59e71a1 (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
# frozen_string_literal: true

require 'fast_spec_helper'
require 'rubocop'
require_relative '../../../support/helpers/expect_offense'
require_relative '../../../../rubocop/cop/scalability/idempotent_worker'

describe RuboCop::Cop::Scalability::IdempotentWorker do
  include CopHelper
  include ExpectOffense

  subject(:cop) { described_class.new }

  before do
    allow(cop)
      .to receive(:in_worker?)
      .and_return(true)
  end

  it 'adds an offense when not defining idempotent method' do
    inspect_source(<<~CODE.strip_indent)
      class SomeWorker
      end
    CODE

    expect(cop.offenses.size).to eq(1)
  end

  it 'adds an offense when not defining idempotent method' do
    inspect_source(<<~CODE.strip_indent)
      class SomeWorker
        idempotent!
      end
    CODE

    expect(cop.offenses.size).to be_zero
  end
end