2020-05-24 23:13:21 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
require 'rubocop_spec_helper'
|
2020-05-24 23:13:21 +05:30
|
|
|
require_relative '../../../rubocop/cop/avoid_keyword_arguments_in_sidekiq_workers'
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
RSpec.describe RuboCop::Cop::AvoidKeywordArgumentsInSidekiqWorkers do
|
2020-05-24 23:13:21 +05:30
|
|
|
it 'flags violation for keyword arguments usage in perform method signature' do
|
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
def perform(id:)
|
2021-03-11 19:13:27 +05:30
|
|
|
^^^^^^^^^^^^^^^^ Do not use keyword arguments in Sidekiq workers. For details, [...]
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'flags violation for optional keyword arguments usage in perform method signature' do
|
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
def perform(id: nil)
|
2021-03-11 19:13:27 +05:30
|
|
|
^^^^^^^^^^^^^^^^^^^^ Do not use keyword arguments in Sidekiq workers. For details, [...]
|
2020-05-24 23:13:21 +05:30
|
|
|
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
|