2020-05-11 21:09:40 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-17 06:08:43 +00:00
|
|
|
require 'fast_spec_helper'
|
2020-05-11 21:09:40 +00:00
|
|
|
require_relative '../../../rubocop/cop/avoid_keyword_arguments_in_sidekiq_workers'
|
|
|
|
|
2021-01-07 18:10:38 +00:00
|
|
|
RSpec.describe RuboCop::Cop::AvoidKeywordArgumentsInSidekiqWorkers do
|
2020-05-11 21:09:40 +00:00
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
|
|
|
it 'flags violation for keyword arguments usage in perform method signature' do
|
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
def perform(id:)
|
2021-01-26 18:09:30 +00:00
|
|
|
^^^^^^^^^^^^^^^^ Do not use keyword arguments in Sidekiq workers. For details, [...]
|
2020-05-11 21:09:40 +00:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'flags violation for optional keyword arguments usage in perform method signature' do
|
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
def perform(id: nil)
|
2021-01-26 18:09:30 +00:00
|
|
|
^^^^^^^^^^^^^^^^^^^^ Do not use keyword arguments in Sidekiq workers. For details, [...]
|
2020-05-11 21:09:40 +00:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not flag a violation for standard optional arguments usage in perform method signature' do
|
|
|
|
expect_no_offenses(<<~RUBY)
|
|
|
|
def perform(id = nil)
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not flag a violation for keyword arguments usage in non-perform method signatures' do
|
|
|
|
expect_no_offenses(<<~RUBY)
|
|
|
|
def helper(id:)
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not flag a violation for optional keyword arguments usage in non-perform method signatures' do
|
|
|
|
expect_no_offenses(<<~RUBY)
|
|
|
|
def helper(id: nil)
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
end
|