diff options
Diffstat (limited to 'spec/rubocop/cop/lint')
-rw-r--r-- | spec/rubocop/cop/lint/last_keyword_argument_spec.rb | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/spec/rubocop/cop/lint/last_keyword_argument_spec.rb b/spec/rubocop/cop/lint/last_keyword_argument_spec.rb index 5822bf74e8d..826c681a880 100644 --- a/spec/rubocop/cop/lint/last_keyword_argument_spec.rb +++ b/spec/rubocop/cop/lint/last_keyword_argument_spec.rb @@ -4,7 +4,7 @@ require 'fast_spec_helper' require 'rubocop' require_relative '../../../../rubocop/cop/lint/last_keyword_argument' -RSpec.describe RuboCop::Cop::Lint::LastKeywordArgument, type: :rubocop do +RSpec.describe RuboCop::Cop::Lint::LastKeywordArgument do include CopHelper subject(:cop) { described_class.new } @@ -38,6 +38,8 @@ RSpec.describe RuboCop::Cop::Lint::LastKeywordArgument, type: :rubocop do - | DEPRECATION WARNING: /Users/tkuah/code/ee-gdk/gitlab/create_service.rb:1: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call /Users/tkuah/code/ee-gdk/gitlab/user.rb:17: warning: The called method `call' is defined here + - | + DEPRECATION WARNING: /Users/tkuah/code/ee-gdk/gitlab/other_warning_type.rb:1: warning: Some other warning type YAML end @@ -62,7 +64,7 @@ RSpec.describe RuboCop::Cop::Lint::LastKeywordArgument, type: :rubocop do allow(File).to receive(:read).and_return(create_spec_yaml, projects_spec_yaml) end - it 'registers an offense' do + it 'registers an offense for last keyword warning' do expect_offense(<<~SOURCE, 'create_service.rb') users.call(params) ^^^^^^ Using the last argument as keyword parameters is deprecated @@ -73,6 +75,12 @@ RSpec.describe RuboCop::Cop::Lint::LastKeywordArgument, type: :rubocop do SOURCE end + it 'does not register an offense for other warning types' do + expect_no_offenses(<<~SOURCE, 'other_warning_type.rb') + users.call(params) + SOURCE + end + it 'registers an offense for the new method call' do expect_offense(<<~SOURCE, 'projects_spec.rb') Project.new(params) @@ -95,6 +103,23 @@ RSpec.describe RuboCop::Cop::Lint::LastKeywordArgument, type: :rubocop do SOURCE end + it 'registers an offense on the last non-block argument' do + expect_offense(<<~SOURCE, 'create_service.rb') + users.call(id, params, &block) + ^^^^^^ Using the last argument as keyword parameters is deprecated + SOURCE + + expect_correction(<<~SOURCE) + users.call(id, **params, &block) + SOURCE + end + + it 'does not register an offense if the only argument is a block argument' do + expect_no_offenses(<<~SOURCE, 'create_service.rb') + users.call(&block) + SOURCE + end + it 'registers an offense and corrects by converting splat to double splat' do expect_offense(<<~SOURCE, 'create_service.rb') users.call(id, *params) |