rubocop-minitest 0.15.1 → 0.17.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +9 -9
- data/.github/PULL_REQUEST_TEMPLATE.md +3 -4
- data/.github/workflows/spell_checking.yml +33 -0
- data/.rubocop.yml +2 -3
- data/.rubocop_todo.yml +2 -0
- data/.yardopts +3 -0
- data/CHANGELOG.md +30 -0
- data/CONTRIBUTING.md +3 -2
- data/Gemfile +4 -1
- data/LICENSE.txt +1 -1
- data/Rakefile +4 -6
- data/codespell.txt +0 -0
- data/config/default.yml +13 -2
- data/docs/antora.yml +1 -1
- data/docs/modules/ROOT/pages/cops_minitest.adoc +99 -4
- data/docs/modules/ROOT/pages/installation.adoc +1 -1
- data/lib/rubocop/cop/minitest/assert_empty.rb +12 -0
- data/lib/rubocop/cop/minitest/assert_empty_literal.rb +1 -1
- data/lib/rubocop/cop/minitest/assert_with_expected_argument.rb +3 -2
- data/lib/rubocop/cop/minitest/assertion_in_lifecycle_hook.rb +1 -1
- data/lib/rubocop/cop/minitest/global_expectations.rb +109 -38
- data/lib/rubocop/cop/minitest/multiple_assertions.rb +1 -1
- data/lib/rubocop/cop/minitest/no_assertions.rb +1 -1
- data/lib/rubocop/cop/minitest/refute_empty.rb +12 -0
- data/lib/rubocop/cop/minitest/unreachable_assertion.rb +2 -4
- data/lib/rubocop/cop/mixin/minitest_exploration_helpers.rb +9 -21
- data/lib/rubocop/minitest/assert_offense.rb +183 -0
- data/lib/rubocop/minitest/support.rb +10 -0
- data/lib/rubocop/minitest/version.rb +1 -1
- data/mkdocs.yml +1 -1
- data/relnotes/v0.15.2.md +5 -0
- data/relnotes/v0.16.0.md +11 -0
- data/relnotes/v0.17.0.md +5 -0
- data/relnotes/v0.17.1.md +5 -0
- data/rubocop-minitest.gemspec +2 -1
- data/tasks/changelog.rake +34 -0
- data/tasks/changelog.rb +166 -0
- data/tasks/cops_documentation.rake +5 -15
- data/tasks/cut_release.rake +19 -4
- metadata +16 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06bac8581123850a3beb2e5f9e740279d6ef05889119afd4418d1d079b357b6e
|
4
|
+
data.tar.gz: e0257e30d0b413979b7ce990beae6fc685e3f12161f97ed3fc8391dd023544b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a358ed867fb7a16f3430835a11560c1159940c67b66627db9116d4cf6c45efd2519701f93c8333ed722d1c296bd527ea7b52c970ba472056b7170f363d95ae05
|
7
|
+
data.tar.gz: a22c800e537e5461cb7446d88e60e3a73f7ac63119c72d4acc32d72707670550b16cb7e1f015668d35dcca7a746f947f93df2a4ee6db571ad23f0f0c17766475
|
data/.circleci/config.yml
CHANGED
@@ -30,9 +30,6 @@ jobs:
|
|
30
30
|
- run:
|
31
31
|
name: Check documentation syntax
|
32
32
|
command: bundle exec rake documentation_syntax_check
|
33
|
-
- run:
|
34
|
-
name: Build documentation and verify that doc files are in sync
|
35
|
-
command: bundle exec rake verify_cops_documentation
|
36
33
|
|
37
34
|
workflows:
|
38
35
|
build:
|
@@ -40,19 +37,22 @@ workflows:
|
|
40
37
|
- documentation-checks
|
41
38
|
- rake_default:
|
42
39
|
name: Ruby 2.5
|
43
|
-
image:
|
40
|
+
image: cimg/ruby:2.5
|
44
41
|
- rake_default:
|
45
42
|
name: Ruby 2.6
|
46
|
-
image:
|
43
|
+
image: cimg/ruby:2.6
|
47
44
|
- rake_default:
|
48
45
|
name: Ruby 2.7
|
49
|
-
image:
|
46
|
+
image: cimg/ruby:2.7
|
50
47
|
- rake_default:
|
51
48
|
name: Ruby 3.0
|
52
|
-
image:
|
49
|
+
image: cimg/ruby:3.0
|
50
|
+
- rake_default:
|
51
|
+
name: Ruby 3.1
|
52
|
+
image: cimg/ruby:3.1
|
53
53
|
- rake_default:
|
54
54
|
name: Ruby HEAD
|
55
55
|
image: rubocophq/circleci-ruby-snapshot:latest # Nightly snapshot build
|
56
56
|
- rake_default:
|
57
|
-
name: JRuby 9.
|
58
|
-
image: circleci/jruby:9.
|
57
|
+
name: JRuby 9.3
|
58
|
+
image: circleci/jruby:9.3
|
@@ -5,14 +5,13 @@ The more detailed you are, the better.**
|
|
5
5
|
|
6
6
|
Before submitting the PR make sure the following are checked:
|
7
7
|
|
8
|
+
* [ ] The PR relates to *only* one subject with a clear title and description in grammatically correct, complete sentences.
|
8
9
|
* [ ] Wrote [good commit messages][1].
|
9
10
|
* [ ] Commit message starts with `[Fix #issue-number]` (if the related issue exists).
|
10
11
|
* [ ] Feature branch is up-to-date with `master` (if not - rebase it).
|
11
12
|
* [ ] Squashed related commits together.
|
12
13
|
* [ ] Added tests.
|
13
|
-
* [ ]
|
14
|
-
* [ ]
|
15
|
-
and description in grammatically correct, complete sentences.
|
16
|
-
* [ ] Run `bundle exec rake default`. It executes all tests and RuboCop for itself, and generates the documentation.
|
14
|
+
* [ ] Ran `bundle exec rake default`. It executes all tests and runs RuboCop on its own code.
|
15
|
+
* [ ] Added an entry (file) to the [changelog folder](https://github.com/rubocop/rubocop-minitest/blob/master/changelog/) named `{change_type}_{change_description}.md` if the new code introduces user-observable changes. See [changelog entry format](https://github.com/rubocop/rubocop/blob/master/CONTRIBUTING.md#changelog-entry-format) for details.
|
17
16
|
|
18
17
|
[1]: https://chris.beams.io/posts/git-commit/
|
@@ -0,0 +1,33 @@
|
|
1
|
+
name: Spell Checking
|
2
|
+
|
3
|
+
on: [pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
codespell:
|
7
|
+
name: Check spelling of all files with codespell
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
strategy:
|
10
|
+
matrix:
|
11
|
+
python-version: [3.8]
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
- name: Set up Python ${{ matrix.python-version }}
|
15
|
+
uses: actions/setup-python@v2
|
16
|
+
with:
|
17
|
+
python-version: ${{ matrix.python-version }}
|
18
|
+
- name: Install dependencies
|
19
|
+
run: |
|
20
|
+
python -m pip install --upgrade pip
|
21
|
+
pip install codespell
|
22
|
+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
23
|
+
- name: Check spelling with codespell
|
24
|
+
run: codespell --ignore-words=codespell.txt || exit 1
|
25
|
+
misspell:
|
26
|
+
name: Check spelling of all files in commit with misspell
|
27
|
+
runs-on: ubuntu-latest
|
28
|
+
steps:
|
29
|
+
- uses: actions/checkout@v2
|
30
|
+
- name: Install
|
31
|
+
run: wget -O - -q https://git.io/misspell | sh -s -- -b .
|
32
|
+
- name: Misspell
|
33
|
+
run: git ls-files --empty-directory | xargs ./misspell -error
|
data/.rubocop.yml
CHANGED
@@ -42,6 +42,7 @@ Style/FormatStringToken:
|
|
42
42
|
Metrics/ClassLength:
|
43
43
|
Exclude:
|
44
44
|
- test/**/*
|
45
|
+
- tasks/changelog.rb
|
45
46
|
|
46
47
|
Layout/EndOfLine:
|
47
48
|
EnforcedStyle: lf
|
@@ -79,14 +80,12 @@ Lint/UselessAccessModifier:
|
|
79
80
|
- 'def_matcher'
|
80
81
|
- 'def_node_matcher'
|
81
82
|
|
82
|
-
Lint/BooleanSymbol:
|
83
|
-
Enabled: false
|
84
|
-
|
85
83
|
Metrics/BlockLength:
|
86
84
|
Exclude:
|
87
85
|
- 'Rakefile'
|
88
86
|
- '**/*.rake'
|
89
87
|
- 'test/**/*.rb'
|
88
|
+
- 'rubocop-minitest.gemspec'
|
90
89
|
|
91
90
|
Naming/FileName:
|
92
91
|
Exclude:
|
data/.rubocop_todo.yml
CHANGED
data/.yardopts
ADDED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,35 @@
|
|
2
2
|
|
3
3
|
## master (unreleased)
|
4
4
|
|
5
|
+
## 0.17.1 (2022-01-30)
|
6
|
+
|
7
|
+
### Changes
|
8
|
+
|
9
|
+
* [#158](https://github.com/rubocop/rubocop-minitest/pull/158): Make `Minitest/UnreachableAssertion` aware of `assert` and `refute` prefix methods. ([@koic][])
|
10
|
+
|
11
|
+
## 0.17.0 (2021-11-23)
|
12
|
+
|
13
|
+
### New features
|
14
|
+
|
15
|
+
* [#155](https://github.com/rubocop/rubocop-minitest/issues/155): Provide `assert_offense`, `assert_correction`, and `assert_no_offenses` testing APIs for custom Minitest cop development. ([@koic][])
|
16
|
+
|
17
|
+
## 0.16.0 (2021-11-14)
|
18
|
+
|
19
|
+
### New features
|
20
|
+
|
21
|
+
* [#147](https://github.com/rubocop/rubocop-minitest/issues/147): Add `EnforcedStyle` config parameter for `Minitest/GlobalExpectations`. ([@gi][])
|
22
|
+
|
23
|
+
### Bug fixes
|
24
|
+
|
25
|
+
* [#142](https://github.com/rubocop/rubocop-minitest/issues/142): Fix `Minitest/GlobalExpectations` autocorrect when receiver is lambda. ([@gi][])
|
26
|
+
* [#150](https://github.com/rubocop/rubocop-minitest/issues/150): Fix a false positive for `Minitest/AssertEmpty` and `RefuteEmpty` cops when using `empty` method with any arguments. ([@koic][])
|
27
|
+
|
28
|
+
## 0.15.2 (2021-10-11)
|
29
|
+
|
30
|
+
### Bug fixes
|
31
|
+
|
32
|
+
* [#145](https://github.com/rubocop/rubocop-minitest/pull/145): Mark `Minitest/AssertEmptyLiteral` as safe auto-correction. ([@koic][])
|
33
|
+
|
5
34
|
## 0.15.1 (2021-09-26)
|
6
35
|
|
7
36
|
### Bug fixes
|
@@ -240,3 +269,4 @@
|
|
240
269
|
[@tsmmark]: https://github.com/tsmmark
|
241
270
|
[@cstyles]: https://github.com/cstyles
|
242
271
|
[@ghiculescu]: https://github.com/ghiculescu
|
272
|
+
[@gi]: https://github.com/gi
|
data/CONTRIBUTING.md
CHANGED
@@ -33,7 +33,7 @@ $ rubocop -V
|
|
33
33
|
* If your change has a corresponding open GitHub issue, prefix the commit message with `[Fix #github-issue-number]`.
|
34
34
|
* Make sure to add tests for it. This is important so I don't break it
|
35
35
|
in a future version unintentionally.
|
36
|
-
* Add an entry to the [Changelog](CHANGELOG.md)
|
36
|
+
* Add an entry to the [Changelog](CHANGELOG.md) by creating a file `changelog/{type}_{some_description}.md`. See [changelog entry format](#changelog-entry-format) for details.
|
37
37
|
* Please try not to mess with the Rakefile, version, or history. If
|
38
38
|
you want to have your own version, or is otherwise necessary, that
|
39
39
|
is fine, but please isolate to its own commit so I can cherry-pick
|
@@ -53,12 +53,13 @@ Here are a few examples:
|
|
53
53
|
* New cop `ElseLayout` checks for odd arrangement of code in the `else` branch of a conditional expression. ([@bbatsov][])
|
54
54
|
```
|
55
55
|
|
56
|
+
* Create one file `changelog/{type}_{some_description}.md`, where `type` is `new` (New feature), `fix` or `change`, and `some_description` is unique to avoid conflicts. Task `changelog:fix` (or `:new` or `:change`) can help you.
|
56
57
|
* Mark it up in [Markdown syntax][6].
|
57
58
|
* The entry line should start with `* ` (an asterisk and a space).
|
58
59
|
* If the change has a related GitHub issue (e.g. a bug fix for a reported issue), put a link to the issue as `[#123](https://github.com/rubocop/rubocop-minitest/issues/123): `.
|
59
60
|
* Describe the brief of the change. The sentence should end with a punctuation.
|
60
61
|
* At the end of the entry, add an implicit link to your GitHub user page as `([@username][])`.
|
61
|
-
*
|
62
|
+
* Alternatively, you may modify the CHANGELOG file directly, but this may result in conflicts later on. Also, if this is your first contribution to RuboCop Minitest project, add a link definition for the implicit link to the bottom of the changelog as `[@username]: https://github.com/username`.
|
62
63
|
|
63
64
|
[1]: https://github.com/rubocop/rubocop-minitest/issues
|
64
65
|
[2]: https://www.gun.io/blog/how-to-github-fork-branch-and-pull-request
|
data/Gemfile
CHANGED
@@ -9,5 +9,8 @@ gemspec
|
|
9
9
|
gem 'bump', require: false
|
10
10
|
gem 'rake'
|
11
11
|
gem 'rubocop', github: 'rubocop/rubocop'
|
12
|
-
gem 'rubocop-performance', '~> 1.
|
12
|
+
gem 'rubocop-performance', '~> 1.12.0'
|
13
13
|
gem 'yard', '~> 0.9'
|
14
|
+
|
15
|
+
local_gemfile = File.expand_path('Gemfile.local', __dir__)
|
16
|
+
eval_gemfile local_gemfile if File.exist?(local_gemfile)
|
data/LICENSE.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c) 2019-
|
3
|
+
Copyright (c) 2019-2022 Bozhidar Batsov, Jonas Arvidsson, Koichi ITO
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/Rakefile
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
task release: 'changelog:check_clean' # Before task is required
|
4
|
+
|
3
5
|
require 'bundler'
|
4
6
|
require 'bundler/gem_tasks'
|
5
7
|
|
@@ -28,7 +30,6 @@ RuboCop::RakeTask.new(:internal_investigation)
|
|
28
30
|
|
29
31
|
task default: %i[
|
30
32
|
documentation_syntax_check
|
31
|
-
generate_cops_documentation
|
32
33
|
test
|
33
34
|
internal_investigation
|
34
35
|
]
|
@@ -42,15 +43,12 @@ task :new_cop, [:cop] do |_task, args|
|
|
42
43
|
exit!
|
43
44
|
end
|
44
45
|
|
45
|
-
|
46
|
-
github_user = 'your_id' if github_user.empty?
|
47
|
-
|
48
|
-
generator = RuboCop::Cop::Generator.new(cop_name, github_user)
|
46
|
+
generator = RuboCop::Cop::Generator.new(cop_name)
|
49
47
|
|
50
48
|
generator.write_source
|
51
49
|
generator.write_test
|
52
50
|
generator.inject_require(root_file_path: 'lib/rubocop/cop/minitest_cops.rb')
|
53
|
-
generator.inject_config(config_file_path: 'config/default.yml'
|
51
|
+
generator.inject_config(config_file_path: 'config/default.yml')
|
54
52
|
|
55
53
|
puts generator.todo
|
56
54
|
end
|
data/codespell.txt
ADDED
File without changes
|
data/config/default.yml
CHANGED
@@ -11,9 +11,8 @@ Minitest/AssertEmpty:
|
|
11
11
|
VersionAdded: '0.2'
|
12
12
|
|
13
13
|
Minitest/AssertEmptyLiteral:
|
14
|
-
Description: 'This cop enforces the test to use `assert_empty` instead of using `
|
14
|
+
Description: 'This cop enforces the test to use `assert_empty` instead of using `assert_equal([], object)`.'
|
15
15
|
Enabled: true
|
16
|
-
SafeAutoCorrect: false
|
17
16
|
VersionAdded: '0.5'
|
18
17
|
VersionChanged: '0.11'
|
19
18
|
|
@@ -104,7 +103,19 @@ Minitest/GlobalExpectations:
|
|
104
103
|
Description: 'This cop checks for deprecated global expectations.'
|
105
104
|
StyleGuide: 'https://minitest.rubystyle.guide#global-expectations'
|
106
105
|
Enabled: true
|
106
|
+
EnforcedStyle: any
|
107
|
+
Include:
|
108
|
+
- '**/test/**/*'
|
109
|
+
- '**/*_test.rb'
|
110
|
+
- '**/spec/**/*'
|
111
|
+
- '**/*_spec.rb'
|
112
|
+
SupportedStyles:
|
113
|
+
- _
|
114
|
+
- any
|
115
|
+
- expect
|
116
|
+
- value
|
107
117
|
VersionAdded: '0.7'
|
118
|
+
VersionChanged: '0.16'
|
108
119
|
|
109
120
|
Minitest/LiteralAsActualArgument:
|
110
121
|
Description: 'This cop enforces correct order of `expected` and `actual` arguments for `assert_equal`.'
|
data/docs/antora.yml
CHANGED
@@ -39,13 +39,13 @@ assert_empty(object, 'message')
|
|
39
39
|
|
40
40
|
| Enabled
|
41
41
|
| Yes
|
42
|
-
| Yes
|
42
|
+
| Yes
|
43
43
|
| 0.5
|
44
44
|
| 0.11
|
45
45
|
|===
|
46
46
|
|
47
47
|
This cop enforces the test to use `assert_empty`
|
48
|
-
instead of using `assert_equal([], object)`.
|
48
|
+
instead of using `assert_equal([], object)` or `assert_equal({}, object)`.
|
49
49
|
|
50
50
|
=== Examples
|
51
51
|
|
@@ -458,7 +458,9 @@ assert(actual, 'message')
|
|
458
458
|
This cop tries to detect when a user accidentally used
|
459
459
|
`assert` when they meant to use `assert_equal`.
|
460
460
|
|
461
|
-
|
461
|
+
=== Safety
|
462
|
+
|
463
|
+
This cop is unsafe because it is not possible to determine
|
462
464
|
whether the second argument of `assert` is a message or not.
|
463
465
|
|
464
466
|
=== Examples
|
@@ -517,7 +519,7 @@ end
|
|
517
519
|
| Yes
|
518
520
|
| Yes
|
519
521
|
| 0.7
|
520
|
-
|
|
522
|
+
| 0.16
|
521
523
|
|===
|
522
524
|
|
523
525
|
This cop checks for deprecated global expectations
|
@@ -525,6 +527,54 @@ and autocorrects them to use expect format.
|
|
525
527
|
|
526
528
|
=== Examples
|
527
529
|
|
530
|
+
==== EnforcedStyle: _
|
531
|
+
|
532
|
+
[source,ruby]
|
533
|
+
----
|
534
|
+
# bad
|
535
|
+
musts.must_equal expected_musts
|
536
|
+
wonts.wont_match expected_wonts
|
537
|
+
musts.must_raise TypeError
|
538
|
+
|
539
|
+
expect(musts).must_equal expected_musts
|
540
|
+
expect(wonts).wont_match expected_wonts
|
541
|
+
expect { musts }.must_raise TypeError
|
542
|
+
|
543
|
+
value(musts).must_equal expected_musts
|
544
|
+
value(wonts).wont_match expected_wonts
|
545
|
+
value { musts }.must_raise TypeError
|
546
|
+
|
547
|
+
# good
|
548
|
+
_(musts).must_equal expected_musts
|
549
|
+
_(wonts).wont_match expected_wonts
|
550
|
+
_ { musts }.must_raise TypeError
|
551
|
+
----
|
552
|
+
|
553
|
+
==== EnforcedStyle: any (default)
|
554
|
+
|
555
|
+
[source,ruby]
|
556
|
+
----
|
557
|
+
# bad
|
558
|
+
musts.must_equal expected_musts
|
559
|
+
wonts.wont_match expected_wonts
|
560
|
+
musts.must_raise TypeError
|
561
|
+
|
562
|
+
# good
|
563
|
+
_(musts).must_equal expected_musts
|
564
|
+
_(wonts).wont_match expected_wonts
|
565
|
+
_ { musts }.must_raise TypeError
|
566
|
+
|
567
|
+
expect(musts).must_equal expected_musts
|
568
|
+
expect(wonts).wont_match expected_wonts
|
569
|
+
expect { musts }.must_raise TypeError
|
570
|
+
|
571
|
+
value(musts).must_equal expected_musts
|
572
|
+
value(wonts).wont_match expected_wonts
|
573
|
+
value { musts }.must_raise TypeError
|
574
|
+
----
|
575
|
+
|
576
|
+
==== EnforcedStyle: expect
|
577
|
+
|
528
578
|
[source,ruby]
|
529
579
|
----
|
530
580
|
# bad
|
@@ -532,12 +582,57 @@ musts.must_equal expected_musts
|
|
532
582
|
wonts.wont_match expected_wonts
|
533
583
|
musts.must_raise TypeError
|
534
584
|
|
585
|
+
_(musts).must_equal expected_musts
|
586
|
+
_(wonts).wont_match expected_wonts
|
587
|
+
_ { musts }.must_raise TypeError
|
588
|
+
|
589
|
+
value(musts).must_equal expected_musts
|
590
|
+
value(wonts).wont_match expected_wonts
|
591
|
+
value { musts }.must_raise TypeError
|
592
|
+
|
535
593
|
# good
|
594
|
+
expect(musts).must_equal expected_musts
|
595
|
+
expect(wonts).wont_match expected_wonts
|
596
|
+
expect { musts }.must_raise TypeError
|
597
|
+
----
|
598
|
+
|
599
|
+
==== EnforcedStyle: value
|
600
|
+
|
601
|
+
[source,ruby]
|
602
|
+
----
|
603
|
+
# bad
|
604
|
+
musts.must_equal expected_musts
|
605
|
+
wonts.wont_match expected_wonts
|
606
|
+
musts.must_raise TypeError
|
607
|
+
|
536
608
|
_(musts).must_equal expected_musts
|
537
609
|
_(wonts).wont_match expected_wonts
|
538
610
|
_ { musts }.must_raise TypeError
|
611
|
+
|
612
|
+
expect(musts).must_equal expected_musts
|
613
|
+
expect(wonts).wont_match expected_wonts
|
614
|
+
expect { musts }.must_raise TypeError
|
615
|
+
|
616
|
+
# good
|
617
|
+
value(musts).must_equal expected_musts
|
618
|
+
value(wonts).wont_match expected_wonts
|
619
|
+
value { musts }.must_raise TypeError
|
539
620
|
----
|
540
621
|
|
622
|
+
=== Configurable attributes
|
623
|
+
|
624
|
+
|===
|
625
|
+
| Name | Default value | Configurable values
|
626
|
+
|
627
|
+
| EnforcedStyle
|
628
|
+
| `any`
|
629
|
+
| `_`, `any`, `expect`, `value`
|
630
|
+
|
631
|
+
| Include
|
632
|
+
| `+**/test/**/*+`, `+**/*_test.rb+`, `+**/spec/**/*+`, `+**/*_spec.rb+`
|
633
|
+
| Array
|
634
|
+
|===
|
635
|
+
|
541
636
|
=== References
|
542
637
|
|
543
638
|
* https://minitest.rubystyle.guide#global-expectations
|
@@ -19,6 +19,18 @@ module RuboCop
|
|
19
19
|
extend MinitestCopRule
|
20
20
|
|
21
21
|
define_rule :assert, target_method: :empty?
|
22
|
+
|
23
|
+
remove_method :on_send
|
24
|
+
def on_send(node)
|
25
|
+
return unless node.method?(:assert)
|
26
|
+
return unless (arguments = peel_redundant_parentheses_from(node.arguments))
|
27
|
+
return unless arguments.first.respond_to?(:method?) && arguments.first.method?(:empty?)
|
28
|
+
return unless arguments.first.arguments.empty?
|
29
|
+
|
30
|
+
add_offense(node, message: offense_message(arguments)) do |corrector|
|
31
|
+
autocorrect(corrector, node, arguments)
|
32
|
+
end
|
33
|
+
end
|
22
34
|
end
|
23
35
|
end
|
24
36
|
end
|
@@ -6,8 +6,9 @@ module RuboCop
|
|
6
6
|
# This cop tries to detect when a user accidentally used
|
7
7
|
# `assert` when they meant to use `assert_equal`.
|
8
8
|
#
|
9
|
-
#
|
10
|
-
#
|
9
|
+
# @safety
|
10
|
+
# This cop is unsafe because it is not possible to determine
|
11
|
+
# whether the second argument of `assert` is a message or not.
|
11
12
|
#
|
12
13
|
# @example
|
13
14
|
# # bad
|
@@ -30,7 +30,7 @@ module RuboCop
|
|
30
30
|
|
31
31
|
lifecycle_hooks(class_node).each do |hook_node|
|
32
32
|
hook_node.each_descendant(:send) do |node|
|
33
|
-
if
|
33
|
+
if assertion_method?(node)
|
34
34
|
message = format(MSG, assertion: node.method_name, hook: hook_node.method_name)
|
35
35
|
add_offense(node, message: message)
|
36
36
|
end
|