rubocop-minitest 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: c3c643f7623a14a4a99f813daf392e31a491b7177504cad25760093d80e0b32e
4
- data.tar.gz: b2e5de6e39a741828ae69ca48311b366747bb19aebbc85b23c96ff346f180b39
2
+ SHA1:
3
+ metadata.gz: b6f7bc7c5d1f40800643ddc8cfbdb5b3b716484e
4
+ data.tar.gz: d2f4fedb8db4422c4f601a4410b04b77ef51bf12
5
5
  SHA512:
6
- metadata.gz: eada0f53e4b625d321342f22aa80942512fcefa2131443a7d7d1d7a6f9fafabc1f1e8659f7b7fd2cc002bf83dcec037e760def29db035ac2f1e29bb6ace5fba3
7
- data.tar.gz: ca010bc26330c8c32a9a28fe12f27870affa6e554c6832b6eedede0daf4c89fd5e28ffd93bca1e152a5e3785240023db9e4d35226f3e1bcfc02f49a7cffc5c68
6
+ metadata.gz: 0eaa51499fa109978fae23597f05cb11c0003fb7a4d887249b17c4966f6a2422aec2ee29c2c62baa044b006eb2965076072c306a3863b821382019324274c549
7
+ data.tar.gz: 79225d37425d04fcc425ad661b7970b99ab291f93f2337cf7cb7008ffa55aeb9d29cc0a79d9129f1e089c7eb5f00af95187b785a002f63ffde8b92ea0cd0df52
data/.circleci/config.yml CHANGED
@@ -35,6 +35,9 @@ workflows:
35
35
  - rake_default:
36
36
  name: Ruby 2.6
37
37
  image: circleci/ruby:2.6
38
+ - rake_default:
39
+ name: Ruby 2.7
40
+ image: circleci/ruby:2.7
38
41
  - rake_default:
39
42
  name: Ruby HEAD
40
43
  image: rubocophq/circleci-ruby-snapshot:latest # Nightly snapshot build
data/CHANGELOG.md CHANGED
@@ -2,8 +2,16 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 0.6.0 (2020-02-07)
6
+
7
+ ### New features
8
+
9
+ * [#49](https://github.com/rubocop-hq/rubocop-minitest/pull/49): New cops `AssertMatch` and `RefuteMatch` check for use of `assert_match`/`refute_match` instead of `assert(foo.match(bar))`/`refute(foo.match(bar))`. ([@fsateler][])
10
+
5
11
  ## 0.5.1 (2019-12-25)
6
12
 
13
+ ### Bug fixes
14
+
7
15
  * [#42](https://github.com/rubocop-hq/rubocop-minitest/issues/42): Fix an incorrect autocorrect for some cops of `Minitest` department when using heredoc message. ([@koic][])
8
16
 
9
17
  ## 0.5.0 (2019-11-24)
@@ -72,3 +80,4 @@
72
80
  [@tejasbubane]: https://github.com/tejasbubane
73
81
  [@abhaynikam]: https://github.com/abhaynikam
74
82
  [@herwinw]: https://github.com/herwinw
83
+ [@fsateler]: https://github.com/fsateler
data/Gemfile CHANGED
@@ -10,7 +10,4 @@ gem 'bump', require: false
10
10
  gem 'rake'
11
11
  gem 'rubocop', github: 'rubocop-hq/rubocop'
12
12
  gem 'rubocop-performance', '~> 1.5.0'
13
- # Workaround for YARD 0.9.20 or lower.
14
- # It specifies `github` until the release that includes the following changes:
15
- # https://github.com/lsegal/yard/pull/1290
16
- gem 'yard', github: 'lsegal/yard', ref: '10a2e5b'
13
+ gem 'yard', '~> 0.9'
data/README.md CHANGED
@@ -16,8 +16,8 @@ gem install rubocop-minitest
16
16
 
17
17
  or if you use bundler put this in your `Gemfile`
18
18
 
19
- ```
20
- gem 'rubocop-minitest'
19
+ ```ruby
20
+ gem 'rubocop-minitest', require: false
21
21
  ```
22
22
 
23
23
  ## Usage
data/config/default.yml CHANGED
@@ -20,6 +20,12 @@ Minitest/AssertEqual:
20
20
  Enabled: true
21
21
  VersionAdded: '0.4'
22
22
 
23
+ Minitest/AssertMatch:
24
+ Description: 'This cop enforces the test to use `assert_match` instead of using `assert(matcher.match(object))`.'
25
+ StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#assert-match'
26
+ Enabled: true
27
+ VersionAdded: '0.6'
28
+
23
29
  Minitest/AssertIncludes:
24
30
  Description: 'This cop enforces the test to use `assert_includes` instead of using `assert(collection.include?(object))`.'
25
31
  StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#assert-includes'
@@ -74,6 +80,12 @@ Minitest/RefuteIncludes:
74
80
  Enabled: true
75
81
  VersionAdded: '0.3'
76
82
 
83
+ Minitest/RefuteMatch:
84
+ Description: 'This cop enforces the test to use `refute_match` instead of using `refute(matcher.match(object))`.'
85
+ StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#refute-match'
86
+ Enabled: true
87
+ VersionAdded: '0.6'
88
+
77
89
  Minitest/RefuteInstanceOf:
78
90
  Description: 'This cop enforces the test to use `refute_instance_of(Class, object)` over `refute(object.instance_of?(Class))`.'
79
91
  StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#refute-instance-of'
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Minitest
6
+ # This cop enforces the test to use `assert_match`
7
+ # instead of using `assert(matcher.match(string))`.
8
+ #
9
+ # @example
10
+ # # bad
11
+ # assert(matcher.match(string))
12
+ # assert(matcher.match(string), 'the message')
13
+ #
14
+ # # good
15
+ # assert_match(regex, string)
16
+ # assert_match(matcher, string, 'the message')
17
+ #
18
+ class AssertMatch < Cop
19
+ include ArgumentRangeHelper
20
+
21
+ MSG = 'Prefer using `assert_match(%<arguments>s)` over ' \
22
+ '`assert(%<receiver>s)`.'
23
+
24
+ def_node_matcher :assert_with_match, <<~PATTERN
25
+ (send nil? :assert $(send $_ :match $_) $...)
26
+ PATTERN
27
+
28
+ def on_send(node)
29
+ assert_with_match(node) do
30
+ |first_receiver_arg, matcher, actual, rest_receiver_arg|
31
+ message = rest_receiver_arg.first
32
+ arguments = node_arguments(matcher, actual, message)
33
+ receiver = [first_receiver_arg.source, message&.source].compact.join(', ')
34
+
35
+ offense_message = format(MSG, arguments: arguments, receiver: receiver)
36
+
37
+ add_offense(node, message: offense_message)
38
+ end
39
+ end
40
+
41
+ def autocorrect(node)
42
+ lambda do |corrector|
43
+ assert_with_match(node) do |_, matcher, actual|
44
+ corrector.replace(node.loc.selector, 'assert_match')
45
+
46
+ replacement = [matcher, actual].map(&:source).join(', ')
47
+ corrector.replace(first_argument_range(node), replacement)
48
+ end
49
+ end
50
+ end
51
+
52
+ private
53
+
54
+ def node_arguments(matcher, actual, message)
55
+ [matcher.source, actual.source, message&.source].compact.join(', ')
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Minitest
6
+ # This cop enforces the test to use `refute_match`
7
+ # instead of using `refute(matcher.match(string))`.
8
+ #
9
+ # @example
10
+ # # bad
11
+ # refute(matcher.match(string))
12
+ # refute(matcher.match(string), 'the message')
13
+ #
14
+ # # good
15
+ # refute_match(matcher, string)
16
+ # refute_match(matcher, string, 'the message')
17
+ #
18
+ class RefuteMatch < Cop
19
+ include ArgumentRangeHelper
20
+
21
+ MSG = 'Prefer using `refute_match(%<arguments>s)` over ' \
22
+ '`refute(%<receiver>s)`.'
23
+
24
+ def_node_matcher :refute_with_match, <<~PATTERN
25
+ (send nil? :refute $(send $_ :match $_) $...)
26
+ PATTERN
27
+
28
+ def on_send(node)
29
+ refute_with_match(node) do
30
+ |first_receiver_arg, matcher, actual, rest_receiver_arg|
31
+ message = rest_receiver_arg.first
32
+ arguments = node_arguments(matcher, actual, message)
33
+ receiver = [first_receiver_arg.source, message&.source].compact.join(', ')
34
+
35
+ offense_message = format(MSG, arguments: arguments, receiver: receiver)
36
+
37
+ add_offense(node, message: offense_message)
38
+ end
39
+ end
40
+
41
+ def autocorrect(node)
42
+ lambda do |corrector|
43
+ refute_with_match(node) do |_, matcher, actual|
44
+ corrector.replace(node.loc.selector, 'refute_match')
45
+
46
+ replacement = [matcher, actual].map(&:source).join(', ')
47
+ corrector.replace(first_argument_range(node), replacement)
48
+ end
49
+ end
50
+ end
51
+
52
+ private
53
+
54
+ def node_arguments(matcher, actual, message)
55
+ [matcher.source, actual.source, message&.source].compact.join(', ')
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -7,6 +7,7 @@ require_relative 'minitest/assert_equal'
7
7
  require_relative 'minitest/assert_nil'
8
8
  require_relative 'minitest/assert_includes'
9
9
  require_relative 'minitest/assert_instance_of'
10
+ require_relative 'minitest/assert_match'
10
11
  require_relative 'minitest/assert_respond_to'
11
12
  require_relative 'minitest/assert_truthy'
12
13
  require_relative 'minitest/refute_empty'
@@ -14,5 +15,6 @@ require_relative 'minitest/refute_false'
14
15
  require_relative 'minitest/refute_equal'
15
16
  require_relative 'minitest/refute_nil'
16
17
  require_relative 'minitest/refute_includes'
18
+ require_relative 'minitest/refute_match'
17
19
  require_relative 'minitest/refute_instance_of'
18
20
  require_relative 'minitest/refute_respond_to'
@@ -8,7 +8,7 @@ module RuboCop
8
8
  def self.defaults!
9
9
  path = CONFIG_DEFAULT.to_s
10
10
  hash = ConfigLoader.send(:load_yaml_configuration, path)
11
- config = Config.new(hash, path)
11
+ config = Config.new(hash, path).tap(&:make_excludes_absolute)
12
12
  puts "configuration from #{path}" if ConfigLoader.debug?
13
13
  config = ConfigLoader.merge_with_default(config, path)
14
14
  ConfigLoader.instance_variable_set(:@default_configuration, config)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Minitest
5
- VERSION = '0.5.1'
5
+ VERSION = '0.6.0'
6
6
  end
7
7
  end
data/manual/cops.md CHANGED
@@ -6,6 +6,7 @@
6
6
  * [Minitest/AssertEqual](cops_minitest.md#minitestassertequal)
7
7
  * [Minitest/AssertIncludes](cops_minitest.md#minitestassertincludes)
8
8
  * [Minitest/AssertInstanceOf](cops_minitest.md#minitestassertinstanceof)
9
+ * [Minitest/AssertMatch](cops_minitest.md#minitestassertmatch)
9
10
  * [Minitest/AssertNil](cops_minitest.md#minitestassertnil)
10
11
  * [Minitest/AssertRespondTo](cops_minitest.md#minitestassertrespondto)
11
12
  * [Minitest/AssertTruthy](cops_minitest.md#minitestasserttruthy)
@@ -14,6 +15,7 @@
14
15
  * [Minitest/RefuteFalse](cops_minitest.md#minitestrefutefalse)
15
16
  * [Minitest/RefuteIncludes](cops_minitest.md#minitestrefuteincludes)
16
17
  * [Minitest/RefuteInstanceOf](cops_minitest.md#minitestrefuteinstanceof)
18
+ * [Minitest/RefuteMatch](cops_minitest.md#minitestrefutematch)
17
19
  * [Minitest/RefuteNil](cops_minitest.md#minitestrefutenil)
18
20
  * [Minitest/RefuteRespondTo](cops_minitest.md#minitestrefuterespondto)
19
21
 
@@ -118,6 +118,31 @@ assert_instance_of(Class, object, 'the message')
118
118
 
119
119
  * [https://github.com/rubocop-hq/minitest-style-guide#assert-instance-of](https://github.com/rubocop-hq/minitest-style-guide#assert-instance-of)
120
120
 
121
+ ## Minitest/AssertMatch
122
+
123
+ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
124
+ --- | --- | --- | --- | ---
125
+ Enabled | Yes | Yes | 0.6 | -
126
+
127
+ This cop enforces the test to use `assert_match`
128
+ instead of using `assert(matcher.match(string))`.
129
+
130
+ ### Examples
131
+
132
+ ```ruby
133
+ # bad
134
+ assert(matcher.match(string))
135
+ assert(matcher.match(string), 'the message')
136
+
137
+ # good
138
+ assert_match(regex, string)
139
+ assert_match(matcher, string, 'the message')
140
+ ```
141
+
142
+ ### References
143
+
144
+ * [https://github.com/rubocop-hq/minitest-style-guide#assert-match](https://github.com/rubocop-hq/minitest-style-guide#assert-match)
145
+
121
146
  ## Minitest/AssertNil
122
147
 
123
148
  Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
@@ -319,6 +344,31 @@ refute_instance_of(Class, object, 'the message')
319
344
 
320
345
  * [https://github.com/rubocop-hq/minitest-style-guide#refute-instance-of](https://github.com/rubocop-hq/minitest-style-guide#refute-instance-of)
321
346
 
347
+ ## Minitest/RefuteMatch
348
+
349
+ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
350
+ --- | --- | --- | --- | ---
351
+ Enabled | Yes | Yes | 0.6 | -
352
+
353
+ This cop enforces the test to use `refute_match`
354
+ instead of using `refute(matcher.match(string))`.
355
+
356
+ ### Examples
357
+
358
+ ```ruby
359
+ # bad
360
+ refute(matcher.match(string))
361
+ refute(matcher.match(string), 'the message')
362
+
363
+ # good
364
+ refute_match(matcher, string)
365
+ refute_match(matcher, string, 'the message')
366
+ ```
367
+
368
+ ### References
369
+
370
+ * [https://github.com/rubocop-hq/minitest-style-guide#refute-match](https://github.com/rubocop-hq/minitest-style-guide#refute-match)
371
+
322
372
  ## Minitest/RefuteNil
323
373
 
324
374
  Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
data/relnotes/v0.5.1.md CHANGED
@@ -1,3 +1,5 @@
1
+ ### Bug fixes
2
+
1
3
  * [#42](https://github.com/rubocop-hq/rubocop-minitest/issues/42): Fix an incorrect autocorrect for some cops of `Minitest` department when using heredoc message. ([@koic][])
2
4
 
3
5
  [@koic]: https://github.com/koic
@@ -0,0 +1,5 @@
1
+ ### New features
2
+
3
+ * [#49](https://github.com/rubocop-hq/rubocop-minitest/pull/49): New cops `AssertMatch` and `RefuteMatch` check for use of `assert_match`/`refute_match` instead of `assert(foo.match(bar))`/`refute(foo.match(bar))`. ([@fsateler][])
4
+
5
+ [@fsateler]: https://github.com/fsateler
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-minitest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2019-12-25 00:00:00.000000000 Z
13
+ date: 2020-02-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop
@@ -71,6 +71,7 @@ files:
71
71
  - lib/rubocop/cop/minitest/assert_equal.rb
72
72
  - lib/rubocop/cop/minitest/assert_includes.rb
73
73
  - lib/rubocop/cop/minitest/assert_instance_of.rb
74
+ - lib/rubocop/cop/minitest/assert_match.rb
74
75
  - lib/rubocop/cop/minitest/assert_nil.rb
75
76
  - lib/rubocop/cop/minitest/assert_respond_to.rb
76
77
  - lib/rubocop/cop/minitest/assert_truthy.rb
@@ -79,6 +80,7 @@ files:
79
80
  - lib/rubocop/cop/minitest/refute_false.rb
80
81
  - lib/rubocop/cop/minitest/refute_includes.rb
81
82
  - lib/rubocop/cop/minitest/refute_instance_of.rb
83
+ - lib/rubocop/cop/minitest/refute_match.rb
82
84
  - lib/rubocop/cop/minitest/refute_nil.rb
83
85
  - lib/rubocop/cop/minitest/refute_respond_to.rb
84
86
  - lib/rubocop/cop/minitest_cops.rb
@@ -101,6 +103,7 @@ files:
101
103
  - relnotes/v0.4.1.md
102
104
  - relnotes/v0.5.0.md
103
105
  - relnotes/v0.5.1.md
106
+ - relnotes/v0.6.0.md
104
107
  - rubocop-minitest.gemspec
105
108
  - tasks/cops_documentation.rake
106
109
  - tasks/cut_release.rake
@@ -128,7 +131,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
131
  - !ruby/object:Gem::Version
129
132
  version: '0'
130
133
  requirements: []
131
- rubygems_version: 3.1.2
134
+ rubyforge_project:
135
+ rubygems_version: 2.5.2.3
132
136
  signing_key:
133
137
  specification_version: 4
134
138
  summary: Automatic Minitest code style checking tool.