Skip to content

Commit

Permalink
Make InternalAffairs/ExampleDescription aware of an improper descri…
Browse files Browse the repository at this point in the history
…ption
  • Loading branch information
koic committed Apr 22, 2024
1 parent 5706ac0 commit a35ef47
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/rubocop/cop/internal_affairs/example_description.rb
Expand Up @@ -46,7 +46,7 @@ class ExampleDescription < Base
/\A(does not|doesn't) (register|find|flag|report)/ => 'registers',
/\A(does not|doesn't) add (a|an|any )?offense/ => 'registers an offense',
/\Aregisters no offense/ => 'registers an offense',
/\Aaccepts\b/ => 'registers'
/\A(accepts|register)\b/ => 'registers'
}.freeze

EXPECT_NO_CORRECTIONS_DESCRIPTION_MAPPING = {
Expand Down
15 changes: 15 additions & 0 deletions spec/rubocop/cop/internal_affairs/example_description_spec.rb
Expand Up @@ -77,6 +77,21 @@
RUBY
end

it 'registers an offense when given an improper description for `register`' do
expect_offense(<<~RUBY)
it 'register the case' do
^^^^^^^^^^^^^^^^^^^ Description does not match use of `expect_offense`.
expect_offense('code')
end
RUBY

expect_correction(<<~RUBY)
it 'registers the case' do
expect_offense('code')
end
RUBY
end

it 'does not register an offense when given a proper description' do
expect_no_offenses(<<~RUBY)
it 'finds an offense' do
Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cop/layout/empty_comment_spec.rb
Expand Up @@ -143,7 +143,7 @@ def foo
RUBY
end

it 'register offenses and correct multiple empty comments next to code' do
it 'registers offenses and correct multiple empty comments next to code' do
expect_offense(<<~RUBY)
def foo #
^ Source code comment is empty.
Expand All @@ -159,7 +159,7 @@ def foo
RUBY
end

it 'register offenses and correct multiple aligned empty comments next to code' do
it 'registers offenses and correct multiple aligned empty comments next to code' do
expect_offense(<<~RUBY)
def foo #
^ Source code comment is empty.
Expand Down
6 changes: 3 additions & 3 deletions spec/rubocop/cop/layout/extra_spacing_spec.rb
Expand Up @@ -461,7 +461,7 @@ def batch
RUBY
end

it 'register offenses and correct consecutive operator assignments which are not aligned' do
it 'registers offenses and correct consecutive operator assignments which are not aligned' do
expect_offense(<<~RUBY)
a += 1
bb = 2
Expand Down Expand Up @@ -512,7 +512,7 @@ def batch
RUBY
end

it 'register offenses and correct consecutive attribute assignments which are not aligned' do
it 'registers offenses and correct consecutive attribute assignments which are not aligned' do
expect_offense(<<~RUBY)
a.attr = 1
bb &&= 2
Expand All @@ -538,7 +538,7 @@ def batch
RUBY
end

it 'register offenses and correct complex nested assignments' do
it 'registers offenses and correct complex nested assignments' do
expect_offense(<<~RUBY)
def batch
@areas = params[:param].map {
Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cop/layout/hash_alignment_spec.rb
Expand Up @@ -180,7 +180,7 @@ def example
context 'when `EnforcedStyle: with_fixed_indentation` of `ArgumentAlignment`' do
let(:argument_alignment_config) { { 'EnforcedStyle' => 'with_fixed_indentation' } }

it 'register and corrects an offense' do
it 'registers and corrects an offense' do
expect_offense(<<~RUBY)
THINGS = {
oh: :io,
Expand Down Expand Up @@ -221,7 +221,7 @@ def example
end

context 'when using hash value omission', :ruby31 do
it 'register and corrects an offense' do
it 'registers and corrects an offense' do
expect_offense(<<~RUBY)
THINGS = {
oh:,
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/cop/layout/space_in_lambda_literal_spec.rb
Expand Up @@ -131,7 +131,7 @@
RUBY
end

it 'register offenses and correct spaces in both lambdas when nested' do
it 'registers offenses and correct spaces in both lambdas when nested' do
expect_offense(<<~RUBY)
a = -> (b = -> (c) {}, d) { b + d }
^ Do not use spaces between `->` and `(` in lambda literals.
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/cop/layout/space_inside_block_braces_spec.rb
Expand Up @@ -148,7 +148,7 @@
RUBY
end

it 'register offenses and correct both braces without inner space' do
it 'registers offenses and correct both braces without inner space' do
expect_offense(<<~RUBY)
a {}
b { }
Expand Down
Expand Up @@ -280,7 +280,7 @@ def Vector.[](*array)
RUBY
end

it 'register and correct multiple offenses for multiple sets of ref brackets' do
it 'registers and correct multiple offenses for multiple sets of ref brackets' do
expect_offense(<<~RUBY)
b[ :key]["foo" ][ 0 ]
^ Do not use space inside reference brackets.
Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cop/style/hash_transform_values_spec.rb
Expand Up @@ -238,7 +238,7 @@
RUBY
end

it 'register and corrects an offense _.to_h{...} when value is a hash literal and is enclosed in braces' do
it 'registers and corrects an offense _.to_h{...} when value is a hash literal and is enclosed in braces' do
expect_offense(<<~RUBY)
{a: 1, b: 2}.to_h { |key, val| [key, { value: val }] }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `transform_values` over `to_h {...}`.
Expand All @@ -249,7 +249,7 @@
RUBY
end

it 'register and corrects an offense _.to_h{...} when value is a hash literal and is not enclosed in braces' do
it 'registers and corrects an offense _.to_h{...} when value is a hash literal and is not enclosed in braces' do
expect_offense(<<~RUBY)
{a: 1, b: 2}.to_h { |key, val| [key, value: val] }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `transform_values` over `to_h {...}`.
Expand Down
Expand Up @@ -436,7 +436,7 @@ def foo
RUBY
end

it 'register and corrects an offense when using `if (foo? || bar) && baz?` with boolean literal branches' do
it 'registers and corrects an offense when using `if (foo? || bar) && baz?` with boolean literal branches' do
expect_offense(<<~RUBY)
if (foo? || bar) && baz?
^^ Remove redundant `if` with boolean literal branches.
Expand Down
Expand Up @@ -1000,7 +1000,7 @@ def seatle_style arg: default(42)
}
end

it 'register offense for single-line chaining without previous parens' do
it 'registers offense for single-line chaining without previous parens' do
expect_offense(<<~RUBY)
Rails.convoluted.example.logger.error("something")
^^^^^^^^^^^^^ Omit parentheses for method calls with arguments.
Expand All @@ -1011,7 +1011,7 @@ def seatle_style arg: default(42)
RUBY
end

it 'register offense for multi-line chaining without previous parens' do
it 'registers offense for multi-line chaining without previous parens' do
expect_offense(<<~RUBY)
Rails
.convoluted
Expand Down
10 changes: 5 additions & 5 deletions spec/rubocop/cop/style/trailing_method_end_statement_spec.rb
Expand Up @@ -3,7 +3,7 @@
RSpec.describe RuboCop::Cop::Style::TrailingMethodEndStatement, :config do
let(:config) { RuboCop::Config.new('Layout/IndentationWidth' => { 'Width' => 2 }) }

it 'register offense with trailing end on 2 line method' do
it 'registers offense with trailing end on 2 line method' do
expect_offense(<<~RUBY)
def some_method
foo; end
Expand All @@ -17,7 +17,7 @@ def some_method
RUBY
end

it 'register offense with trailing end on 3 line method' do
it 'registers offense with trailing end on 3 line method' do
expect_offense(<<~RUBY)
def a
b
Expand All @@ -33,7 +33,7 @@ def a
RUBY
end

it 'register offense with trailing end on method with comment' do
it 'registers offense with trailing end on method with comment' do
expect_offense(<<~RUBY)
def c
b = calculation
Expand All @@ -49,7 +49,7 @@ def c
RUBY
end

it 'register offense with trailing end on method with block' do
it 'registers offense with trailing end on method with block' do
expect_offense(<<~RUBY)
def d
block do
Expand All @@ -67,7 +67,7 @@ def d
RUBY
end

it 'register offense with trailing end inside class' do
it 'registers offense with trailing end inside class' do
expect_offense(<<~RUBY)
class Foo
def some_method
Expand Down

0 comments on commit a35ef47

Please sign in to comment.