2020-04-08 14:13:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'fast_spec_helper'
|
|
|
|
require 'rubocop'
|
|
|
|
require_relative '../../../../rubocop/cop/scalability/idempotent_worker'
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
describe RuboCop::Cop::Scalability::IdempotentWorker, type: :rubocop do
|
2020-04-08 14:13:33 +05:30
|
|
|
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
|
2020-06-23 00:09:42 +05:30
|
|
|
inspect_source(<<~CODE)
|
2020-04-08 14:13:33 +05:30
|
|
|
class SomeWorker
|
|
|
|
end
|
|
|
|
CODE
|
|
|
|
|
|
|
|
expect(cop.offenses.size).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds an offense when not defining idempotent method' do
|
2020-06-23 00:09:42 +05:30
|
|
|
inspect_source(<<~CODE)
|
2020-04-08 14:13:33 +05:30
|
|
|
class SomeWorker
|
|
|
|
idempotent!
|
|
|
|
end
|
|
|
|
CODE
|
|
|
|
|
|
|
|
expect(cop.offenses.size).to be_zero
|
|
|
|
end
|
|
|
|
end
|