2019-10-29 08:06:40 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-17 02:08:43 -04:00
|
|
|
require 'fast_spec_helper'
|
2017-09-19 11:25:42 -04:00
|
|
|
|
2017-12-12 11:21:00 -05:00
|
|
|
require 'rubocop'
|
|
|
|
require 'rubocop/rspec/support'
|
2017-09-19 11:25:42 -04:00
|
|
|
|
2017-12-12 11:21:00 -05:00
|
|
|
require_relative '../../../rubocop/cop/include_sidekiq_worker'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe RuboCop::Cop::IncludeSidekiqWorker, type: :rubocop do
|
2017-12-12 11:21:00 -05:00
|
|
|
include CopHelper
|
|
|
|
|
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
|
|
|
context 'when `Sidekiq::Worker` is included' do
|
|
|
|
let(:source) { 'include Sidekiq::Worker' }
|
|
|
|
let(:correct_source) { 'include ApplicationWorker' }
|
|
|
|
|
|
|
|
it 'registers an offense ' do
|
2017-09-19 11:25:42 -04:00
|
|
|
inspect_source(source)
|
2017-12-12 11:21:00 -05:00
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
expect(cop.offenses.size).to eq(1)
|
|
|
|
expect(cop.offenses.map(&:line)).to eq([1])
|
|
|
|
expect(cop.highlights).to eq(['Sidekiq::Worker'])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'autocorrects to the right version' do
|
2017-09-19 11:25:42 -04:00
|
|
|
autocorrected = autocorrect_source(source)
|
2017-12-12 11:21:00 -05:00
|
|
|
|
|
|
|
expect(autocorrected).to eq(correct_source)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|