rubocop-minitest 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee9ffa711b1d8af3e0efded458b42333d3c297e9b2f65ec9dc311e5577398552
4
- data.tar.gz: 801b3f7a5100a60528f8643ece061ad2dab145f0d52335a9cd7070190a03f2ff
3
+ metadata.gz: c5d715a17205c012bd5da344d7a8cd6438334554ee22cb509731756c0be17cb3
4
+ data.tar.gz: f833ffb2d8c3b23e8c7e49b9fc756193e9db5f83668423975201e8a8d52df433
5
5
  SHA512:
6
- metadata.gz: c9568032ba4258bd449864b1cc982d5e1f85b44e862e360b3ad9dcaa3b96ec9c497c51901632015d45b184611cbe4c376fe7786b77ded3197baa0b44e26c4a28
7
- data.tar.gz: 810285b00445e4c90e576f5875d01f151a8d031ac6da3595087e1e6df958464e7d8add79a230a9dd2086c5fd030f5e99153b9011b868eadd4a9fd19c0ed87993
6
+ metadata.gz: 94c2bca0cb05ac331ed6fd20fb2f0d12ef8ebe8866d2b9201ec5a0ef1194a0b4550d3fe4940e976d303dfef643e6258ac8c3f3b9e44b24086b1466f314385fdc
7
+ data.tar.gz: 377e96496bf87ba7ab7d49bffd9abf7b355ff43a2259af03be88bbb214fe389b85c89e1d0f1851f2eee88530bd5bad8cc4b2c252d3c4269f2ccbd686e4b32c05
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## master (unreleased)
2
2
 
3
+ ## 0.2.0 (2019-09-21)
4
+
5
+ ### New features
6
+
7
+ * [#11](https://github.com/rubocop-hq/rubocop-minitest/pull/11): Add new `Minitest/RefuteNil` cop. ([@tejasbubane ][])
8
+ * [#8](https://github.com/rubocop-hq/rubocop-minitest/pull/8): Add new `Minitest/AssertTruthy` cop. ([@abhaynikam ][])
9
+ * [#9](https://github.com/rubocop-hq/rubocop-minitest/pull/9): Add new `Minitest/AssertIncludes` cop. ([@abhaynikam ][])
10
+ * [#10](https://github.com/rubocop-hq/rubocop-minitest/pull/10): Add new `Minitest/AssertEmpty` cop. ([@abhaynikam ][])
11
+
3
12
  ## 0.1.0 (2019-09-01)
4
13
 
5
14
  ### New features
@@ -9,3 +18,5 @@
9
18
 
10
19
  [@koic]: https://github.com/koic
11
20
  [@duduribeiro]: https://github.com/duduribeiro
21
+ [@tejasbubane]: https://github.com/tejasbubane
22
+ [@abhaynikam]: https://github.com/abhaynikam
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # RuboCop Minitest
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/rubocop-minitest.svg)](https://badge.fury.io/rb/rubocop-minitest)
4
+ [![CircleCI](https://circleci.com/gh/rubocop-hq/rubocop-minitest.svg?style=svg)](https://circleci.com/gh/rubocop-hq/rubocop-minitest)
5
+
3
6
  A [RuboCop](https://github.com/rubocop-hq/rubocop) extension focused on enforcing Minitest best practices and coding conventions.
4
7
 
5
8
  ## Installation
data/config/default.yml CHANGED
@@ -7,3 +7,27 @@ Minitest/AssertNil:
7
7
  StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#assert-nil'
8
8
  Enabled: true
9
9
  VersionAdded: '0.1'
10
+
11
+ Minitest/AssertEmpty:
12
+ Description: 'Check if your test uses `assert_empty` instead of `assert(actual.empty?)`.'
13
+ StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#assert-empty'
14
+ Enabled: true
15
+ VersionAdded: '0.2'
16
+
17
+ Minitest/AssertIncludes:
18
+ Description: 'Check if your test uses `assert_includes` instead of `assert(collection.includes?(actual))`.'
19
+ StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#assert-includes'
20
+ Enabled: true
21
+ VersionAdded: '0.2'
22
+
23
+ Minitest/AssertTruthy:
24
+ Description: 'Check if your test uses `assert(actual)` instead of `assert_equal(true, actual)`.'
25
+ StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#assert-truthy'
26
+ Enabled: true
27
+ VersionAdded: '0.2'
28
+
29
+ Minitest/RefuteNil:
30
+ Description: 'Check if your test uses `refute_nil` instead of `refute_equal(nil, something)`.'
31
+ StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#refute-nil'
32
+ Enabled: true
33
+ VersionAdded: '0.2'
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Minitest
6
+ # Check if your test uses `assert_empty` instead of `assert(actual.empty?)`.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # assert(actual.empty?)
11
+ # assert(actual.empty?, 'the message')
12
+ #
13
+ # # good
14
+ # assert_empty(actual)
15
+ # assert_empty(actual, 'the message')
16
+ #
17
+ class AssertEmpty < Cop
18
+ MSG = 'Prefer using `assert_empty(%<arguments>s)` over ' \
19
+ '`assert(%<receiver>s)`.'
20
+
21
+ def_node_matcher :assert_with_empty, <<~PATTERN
22
+ (send nil? :assert $(send $_ :empty?) $...)
23
+ PATTERN
24
+
25
+ def on_send(node)
26
+ assert_with_empty(node) do |first_receiver_arg, actual, rest_receiver_arg|
27
+ message = rest_receiver_arg.first
28
+
29
+ arguments = [actual.source, message&.source].compact.join(', ')
30
+ receiver = [first_receiver_arg.source, message&.source].compact.join(', ')
31
+
32
+ offense_message = format(MSG, arguments: arguments, receiver: receiver)
33
+ add_offense(node, message: offense_message)
34
+ end
35
+ end
36
+
37
+ def autocorrect(node)
38
+ lambda do |corrector|
39
+ assert_with_empty(node) do |_first_receiver_arg, actual, rest_receiver_arg|
40
+ message = rest_receiver_arg.first
41
+
42
+ replacement = [actual.source, message&.source].compact.join(', ')
43
+ corrector.replace(node.loc.expression, "assert_empty(#{replacement})")
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Minitest
6
+ # Check if your test uses `assert_includes`
7
+ # instead of `assert(collection.includes?(actual))`.
8
+ #
9
+ # @example
10
+ # # bad
11
+ # assert(collection.includes?(actual))
12
+ # assert(collection.includes?(actual), 'the message')
13
+ #
14
+ # # good
15
+ # assert_includes(collection, actual)
16
+ # assert_includes(collection, actual, 'the message')
17
+ #
18
+ class AssertIncludes < Cop
19
+ MSG = 'Prefer using `assert_includes(%<arguments>s)` over ' \
20
+ '`assert(%<receiver>s)`.'
21
+
22
+ def_node_matcher :assert_with_includes, <<~PATTERN
23
+ (send nil? :assert $(send $_ :includes? $_) $...)
24
+ PATTERN
25
+
26
+ def on_send(node)
27
+ assert_with_includes(node) do
28
+ |first_receiver_arg, collection, actual, rest_receiver_arg|
29
+
30
+ message = rest_receiver_arg.first
31
+ arguments = node_arguments(collection, actual, message)
32
+ receiver = [first_receiver_arg.source, message&.source].compact.join(', ')
33
+
34
+ offense_message = format(MSG, arguments: arguments, receiver: receiver)
35
+
36
+ add_offense(node, message: offense_message)
37
+ end
38
+ end
39
+
40
+ def autocorrect(node)
41
+ lambda do |corrector|
42
+ assert_with_includes(node) do
43
+ |_receiver, collection, actual, rest_receiver_arg|
44
+
45
+ message = rest_receiver_arg.first
46
+ replacement = node_arguments(collection, actual, message)
47
+ corrector.replace(node.loc.expression, "assert_includes(#{replacement})")
48
+ end
49
+ end
50
+ end
51
+
52
+ private
53
+
54
+ def node_arguments(collection, actual, message)
55
+ [collection.source, actual.source, message&.source].compact.join(', ')
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Minitest
6
+ # Check if your test uses `assert(actual)`
7
+ # instead of `assert_equal(true, actual)`.
8
+ #
9
+ # @example
10
+ # # bad
11
+ # assert_equal(true, actual)
12
+ # assert_equal(true, actual, 'the message')
13
+ #
14
+ # # good
15
+ # assert(actual)
16
+ # assert(actual, 'the message')
17
+ #
18
+ class AssertTruthy < Cop
19
+ MSG = 'Prefer using `assert(%<arguments>s)` over ' \
20
+ '`assert_equal(true, %<arguments>s)`.'
21
+
22
+ def_node_matcher :assert_equal_with_truthy, <<~PATTERN
23
+ (send nil? :assert_equal true $_ $...)
24
+ PATTERN
25
+
26
+ def on_send(node)
27
+ assert_equal_with_truthy(node) do |actual, rest_receiver_arg|
28
+ message = rest_receiver_arg.first
29
+
30
+ arguments = [actual.source, message&.source].compact.join(', ')
31
+
32
+ add_offense(node, message: format(MSG, arguments: arguments))
33
+ end
34
+ end
35
+
36
+ def autocorrect(node)
37
+ lambda do |corrector|
38
+ arguments = node.arguments.reject(&:true_type?)
39
+ replacement = arguments.map(&:source).join(', ')
40
+ corrector.replace(node.loc.expression, "assert(#{replacement})")
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Minitest
6
+ # Check if your test uses `refute_nil` instead of `refute_equal(nil, something)`.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # refute_equal(nil, actual)
11
+ # refute_equal(nil, actual, 'the message')
12
+ #
13
+ # # good
14
+ # refute_nil(actual)
15
+ # refute_nil(actual, 'the message')
16
+ #
17
+ class RefuteNil < Cop
18
+ MSG = 'Prefer using `refute_nil(%<arguments>s)` over ' \
19
+ '`refute_equal(nil, %<arguments>s)`.'
20
+
21
+ def_node_matcher :refute_equal_with_nil, <<~PATTERN
22
+ (send nil? :refute_equal nil $_ $...)
23
+ PATTERN
24
+
25
+ def on_send(node)
26
+ refute_equal_with_nil(node) do |actual, message|
27
+ message = message.first
28
+
29
+ arguments = [actual.source, message&.source].compact.join(', ')
30
+
31
+ add_offense(node, message: format(MSG, arguments: arguments))
32
+ end
33
+ end
34
+
35
+ def autocorrect(node)
36
+ lambda do |corrector|
37
+ arguments = node.arguments.reject(&:nil_type?)
38
+ replacement = arguments.map(&:source).join(', ')
39
+ corrector.replace(node.loc.expression, "refute_nil(#{replacement})")
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,3 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'minitest/assert_empty'
3
4
  require_relative 'minitest/assert_nil'
5
+ require_relative 'minitest/assert_includes'
6
+ require_relative 'minitest/assert_truthy'
7
+ require_relative 'minitest/refute_nil'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Minitest
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
data/manual/cops.md CHANGED
@@ -1,6 +1,10 @@
1
1
  <!-- START_COP_LIST -->
2
2
  #### Department [Minitest](cops_minitest.md)
3
3
 
4
+ * [Minitest/AssertEmpty](cops_minitest.md#minitestassertempty)
5
+ * [Minitest/AssertIncludes](cops_minitest.md#minitestassertincludes)
4
6
  * [Minitest/AssertNil](cops_minitest.md#minitestassertnil)
7
+ * [Minitest/AssertTruthy](cops_minitest.md#minitestasserttruthy)
8
+ * [Minitest/RefuteNil](cops_minitest.md#minitestrefutenil)
5
9
 
6
- <!-- END_COP_LIST -->
10
+ <!-- END_COP_LIST -->
@@ -1,5 +1,54 @@
1
1
  # Minitest
2
2
 
3
+ ## Minitest/AssertEmpty
4
+
5
+ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
6
+ --- | --- | --- | --- | ---
7
+ Enabled | Yes | Yes | 0.2 | -
8
+
9
+ Check if your test uses `assert_empty` instead of `assert(actual.empty?)`.
10
+
11
+ ### Examples
12
+
13
+ ```ruby
14
+ # bad
15
+ assert(actual.empty?)
16
+ assert(actual.empty?, 'the message')
17
+
18
+ # good
19
+ assert_empty(actual)
20
+ assert_empty(actual, 'the message')
21
+ ```
22
+
23
+ ### References
24
+
25
+ * [https://github.com/rubocop-hq/minitest-style-guide#assert-empty](https://github.com/rubocop-hq/minitest-style-guide#assert-empty)
26
+
27
+ ## Minitest/AssertIncludes
28
+
29
+ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
30
+ --- | --- | --- | --- | ---
31
+ Enabled | Yes | Yes | 0.2 | -
32
+
33
+ Check if your test uses `assert_includes`
34
+ instead of `assert(collection.includes?(actual))`.
35
+
36
+ ### Examples
37
+
38
+ ```ruby
39
+ # bad
40
+ assert(collection.includes?(actual))
41
+ assert(collection.includes?(actual), 'the message')
42
+
43
+ # good
44
+ assert_includes(collection, actual)
45
+ assert_includes(collection, actual, 'the message')
46
+ ```
47
+
48
+ ### References
49
+
50
+ * [https://github.com/rubocop-hq/minitest-style-guide#assert-includes](https://github.com/rubocop-hq/minitest-style-guide#assert-includes)
51
+
3
52
  ## Minitest/AssertNil
4
53
 
5
54
  Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
@@ -23,3 +72,52 @@ assert_nil(actual, 'the message')
23
72
  ### References
24
73
 
25
74
  * [https://github.com/rubocop-hq/minitest-style-guide#assert-nil](https://github.com/rubocop-hq/minitest-style-guide#assert-nil)
75
+
76
+ ## Minitest/AssertTruthy
77
+
78
+ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
79
+ --- | --- | --- | --- | ---
80
+ Enabled | Yes | Yes | 0.2 | -
81
+
82
+ Check if your test uses `assert(actual)`
83
+ instead of `assert_equal(true, actual)`.
84
+
85
+ ### Examples
86
+
87
+ ```ruby
88
+ # bad
89
+ assert_equal(true, actual)
90
+ assert_equal(true, actual, 'the message')
91
+
92
+ # good
93
+ assert(actual)
94
+ assert(actual, 'the message')
95
+ ```
96
+
97
+ ### References
98
+
99
+ * [https://github.com/rubocop-hq/minitest-style-guide#assert-truthy](https://github.com/rubocop-hq/minitest-style-guide#assert-truthy)
100
+
101
+ ## Minitest/RefuteNil
102
+
103
+ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
104
+ --- | --- | --- | --- | ---
105
+ Enabled | Yes | Yes | 0.2 | -
106
+
107
+ Check if your test uses `refute_nil` instead of `refute_equal(nil, something)`.
108
+
109
+ ### Examples
110
+
111
+ ```ruby
112
+ # bad
113
+ refute_equal(nil, actual)
114
+ refute_equal(nil, actual, 'the message')
115
+
116
+ # good
117
+ refute_nil(actual)
118
+ refute_nil(actual, 'the message')
119
+ ```
120
+
121
+ ### References
122
+
123
+ * [https://github.com/rubocop-hq/minitest-style-guide#refute-nil](https://github.com/rubocop-hq/minitest-style-guide#refute-nil)
data/mkdocs.yml ADDED
@@ -0,0 +1,13 @@
1
+ site_name: "A RuboCop extension focused on enforcing Minitest best practices and coding conventions."
2
+ repo_url: https://github.com/rubocop-hq/rubocop-minitest
3
+ edit_uri: edit/master/manual/
4
+ copyright: "Copyright &copy; 2019 Bozhidar Batsov, Jonas Arvidsson, Koichi ITO, and RuboCop contributors"
5
+ docs_dir: manual
6
+ pages:
7
+ - Home: index.md
8
+ - Installation: installation.md
9
+ - Usage: usage.md
10
+ - Cops: cops.md
11
+ - Cops Documentation:
12
+ - Minitest Cops: cops_minitest.md
13
+ theme: readthedocs
data/readthedocs.yml ADDED
@@ -0,0 +1,5 @@
1
+ build:
2
+ image: stable
3
+
4
+ formats:
5
+ - htmlzip
@@ -18,10 +18,10 @@ Gem::Specification.new do |spec|
18
18
 
19
19
  spec.required_ruby_version = '>= 2.3.0'
20
20
  spec.metadata = {
21
- 'homepage_uri' => 'https://github.com/rubocop-hq/rubocop-minitest',
21
+ 'homepage_uri' => 'https://docs.rubocop.org/projects/minitest',
22
22
  'changelog_uri' => 'https://github.com/rubocop-hq/rubocop-minitest/blob/master/CHANGELOG.md',
23
23
  'source_code_uri' => 'https://github.com/rubocop-hq/rubocop-minitest',
24
- 'documentation_uri' => 'https://github.com/rubocop-hq/rubocop-minitest/manual',
24
+ 'documentation_uri' => 'https://docs.rubocop.org/projects/minitest',
25
25
  'bug_tracker_uri' => 'https://github.com/rubocop-hq/rubocop-minitest/issues'
26
26
  }
27
27
 
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.1.0
4
+ version: 0.2.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-08-31 00:00:00.000000000 Z
13
+ date: 2019-09-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop
@@ -65,7 +65,11 @@ files:
65
65
  - bin/setup
66
66
  - config/default.yml
67
67
  - lib/rubocop-minitest.rb
68
+ - lib/rubocop/cop/minitest/assert_empty.rb
69
+ - lib/rubocop/cop/minitest/assert_includes.rb
68
70
  - lib/rubocop/cop/minitest/assert_nil.rb
71
+ - lib/rubocop/cop/minitest/assert_truthy.rb
72
+ - lib/rubocop/cop/minitest/refute_nil.rb
69
73
  - lib/rubocop/cop/minitest_cops.rb
70
74
  - lib/rubocop/minitest.rb
71
75
  - lib/rubocop/minitest/inject.rb
@@ -75,16 +79,18 @@ files:
75
79
  - manual/index.md
76
80
  - manual/installation.md
77
81
  - manual/usage.md
82
+ - mkdocs.yml
83
+ - readthedocs.yml
78
84
  - rubocop-minitest.gemspec
79
85
  - tasks/cops_documentation.rake
80
86
  homepage:
81
87
  licenses:
82
88
  - MIT
83
89
  metadata:
84
- homepage_uri: https://github.com/rubocop-hq/rubocop-minitest
90
+ homepage_uri: https://docs.rubocop.org/projects/minitest
85
91
  changelog_uri: https://github.com/rubocop-hq/rubocop-minitest/blob/master/CHANGELOG.md
86
92
  source_code_uri: https://github.com/rubocop-hq/rubocop-minitest
87
- documentation_uri: https://github.com/rubocop-hq/rubocop-minitest/manual
93
+ documentation_uri: https://docs.rubocop.org/projects/minitest
88
94
  bug_tracker_uri: https://github.com/rubocop-hq/rubocop-minitest/issues
89
95
  post_install_message:
90
96
  rdoc_options: []
@@ -101,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
107
  - !ruby/object:Gem::Version
102
108
  version: '0'
103
109
  requirements: []
104
- rubygems_version: 3.0.3
110
+ rubygems_version: 3.0.6
105
111
  signing_key:
106
112
  specification_version: 4
107
113
  summary: Automatic Minitest code style checking tool.