rubocop-rspec 2.14.0 → 2.14.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -1
- data/lib/rubocop/cop/rspec/example_wording.rb +7 -8
- data/lib/rubocop/cop/rspec/factory_bot/consistent_parentheses_style.rb +11 -0
- data/lib/rubocop/cop/rspec/file_path.rb +15 -8
- data/lib/rubocop/cop/rspec/no_expectation_example.rb +1 -1
- data/lib/rubocop/cop/rspec/rails/inferred_spec_type.rb +14 -4
- data/lib/rubocop/cop/rspec/sort_metadata.rb +1 -2
- data/lib/rubocop/rspec/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbd70ea9708a7d87e0a1307234e3ac5cc37cc6197e6b1cc72487342b772ec6f1
|
4
|
+
data.tar.gz: 0c50303e8a0d4218508c51e778d5cb6633b54fe6f823951ea5f8df68d162dfda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e1a6e55fb7aeef036448fe57f03b2d80b796e6971fbd22cd63db496e61b1e211a64e89e987cccc74f5124746713581fb621c805d458f7ff273d436432599483
|
7
|
+
data.tar.gz: 76655025092f103fbd6ca3eda6d466236a8a9857f207e11bc3f8e51c38238367346971c4a0f3feeca6b9069a53fa48bf8281d5dff61f68c6562edce4405a10f0
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,18 @@
|
|
2
2
|
|
3
3
|
## Master (Unreleased)
|
4
4
|
|
5
|
+
## 2.14.2 (2022-10-25)
|
6
|
+
|
7
|
+
- Fix an incorrect autocorrect for `FactoryBot/ConsistentParenthesesStyle` with `omit_parentheses` option when method name and first argument are not on same line. ([@ydah])
|
8
|
+
- Fix autocorrection loop in `RSpec/ExampleWording` for insufficient example wording. ([@pirj])
|
9
|
+
- Fix `RSpec/SortMetadata` not to reorder arguments of `include_`/`it_behaves_like`. ([@pirj])
|
10
|
+
- Fix a false positive for `RSpec/NoExpectationExample` when allowed pattern methods with arguments. ([@ydah])
|
11
|
+
- Change `RSpec/FilePath` so that it only checks suffix when path is under spec/routing or type is defined as routing. ([@r7kamura])
|
12
|
+
|
13
|
+
## 2.14.1 (2022-10-24)
|
14
|
+
|
15
|
+
- Fix an error for `RSpec/Rails/InferredSpecType` with redundant type before other Hash metadata. ([@ydah])
|
16
|
+
|
5
17
|
## 2.14.0 (2022-10-23)
|
6
18
|
|
7
19
|
- Add `require_implicit` style to `RSpec/ImplicitSubject`. ([@r7kamura])
|
@@ -16,7 +28,7 @@
|
|
16
28
|
- Update `config/default.yml` removing deprecated option to make the config correctable by users. ([@ignaciovillaverde])
|
17
29
|
- Do not attempt to auto-correct example groups with `include_examples` in `RSpec/LetBeforeExamples`. ([@pirj])
|
18
30
|
- Add new `RSpec/SortMetadata` cop. ([@leoarnold])
|
19
|
-
- Add support for subject! method to `RSpec/SubjectDeclaration`. ([@ydah]
|
31
|
+
- Add support for subject! method to `RSpec/SubjectDeclaration`. ([@ydah])
|
20
32
|
|
21
33
|
## 2.13.2 (2022-09-23)
|
22
34
|
|
@@ -68,20 +68,15 @@ module RuboCop
|
|
68
68
|
add_wording_offense(description_node, MSG_SHOULD)
|
69
69
|
elsif message.match?(IT_PREFIX)
|
70
70
|
add_wording_offense(description_node, MSG_IT)
|
71
|
-
|
72
|
-
|
71
|
+
elsif insufficient_docstring?(description_node)
|
72
|
+
add_offense(docstring(description_node),
|
73
|
+
message: MSG_INSUFFICIENT_DESCRIPTION)
|
73
74
|
end
|
74
75
|
end
|
75
76
|
end
|
76
77
|
|
77
78
|
private
|
78
79
|
|
79
|
-
def check_and_handle_insufficient_examples(description)
|
80
|
-
if insufficient_examples.include?(preprocess(text(description)))
|
81
|
-
add_wording_offense(description, MSG_INSUFFICIENT_DESCRIPTION)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
80
|
def add_wording_offense(node, message)
|
86
81
|
docstring = docstring(node)
|
87
82
|
|
@@ -137,6 +132,10 @@ module RuboCop
|
|
137
132
|
cop_config.fetch('IgnoredWords', [])
|
138
133
|
end
|
139
134
|
|
135
|
+
def insufficient_docstring?(description_node)
|
136
|
+
insufficient_examples.include?(preprocess(text(description_node)))
|
137
|
+
end
|
138
|
+
|
140
139
|
def insufficient_examples
|
141
140
|
examples = cop_config.fetch('DisallowedExamples', [])
|
142
141
|
examples.map! { |example| preprocess(example) }
|
@@ -30,6 +30,16 @@ module RuboCop
|
|
30
30
|
# create :login
|
31
31
|
# create :login
|
32
32
|
#
|
33
|
+
# # also good
|
34
|
+
# # when method name and first argument are not on same line
|
35
|
+
# create(
|
36
|
+
# :user
|
37
|
+
# )
|
38
|
+
# build(
|
39
|
+
# :user,
|
40
|
+
# name: 'foo'
|
41
|
+
# )
|
42
|
+
#
|
33
43
|
class ConsistentParenthesesStyle < Base
|
34
44
|
extend AutoCorrector
|
35
45
|
include ConfigurableEnforcedStyle
|
@@ -66,6 +76,7 @@ module RuboCop
|
|
66
76
|
|
67
77
|
def process_with_parentheses(node)
|
68
78
|
return unless style == :omit_parentheses
|
79
|
+
return unless same_line?(node, node.first_argument)
|
69
80
|
|
70
81
|
add_offense(node.loc.selector,
|
71
82
|
message: MSG_OMIT_PARENS) do |corrector|
|
@@ -76,8 +76,6 @@ module RuboCop
|
|
76
76
|
return unless top_level_groups.one?
|
77
77
|
|
78
78
|
example_group(node) do |send_node, example_group, arguments|
|
79
|
-
next if routing_spec?(arguments)
|
80
|
-
|
81
79
|
ensure_correct_file_path(send_node, example_group, arguments)
|
82
80
|
end
|
83
81
|
end
|
@@ -85,7 +83,7 @@ module RuboCop
|
|
85
83
|
private
|
86
84
|
|
87
85
|
def ensure_correct_file_path(send_node, example_group, arguments)
|
88
|
-
pattern = pattern_for(example_group, arguments
|
86
|
+
pattern = pattern_for(example_group, arguments)
|
89
87
|
return if filename_ends_with?(pattern)
|
90
88
|
|
91
89
|
# For the suffix shown in the offense message, modify the regular
|
@@ -97,11 +95,13 @@ module RuboCop
|
|
97
95
|
end
|
98
96
|
|
99
97
|
def routing_spec?(args)
|
100
|
-
args.any?(&method(:routing_metadata?))
|
98
|
+
args.any?(&method(:routing_metadata?)) || routing_spec_path?
|
101
99
|
end
|
102
100
|
|
103
|
-
def pattern_for(example_group,
|
104
|
-
|
101
|
+
def pattern_for(example_group, arguments)
|
102
|
+
method_name = arguments.first
|
103
|
+
if spec_suffix_only? || !example_group.const_type? ||
|
104
|
+
routing_spec?(arguments)
|
105
105
|
return pattern_for_spec_suffix_only
|
106
106
|
end
|
107
107
|
|
@@ -149,8 +149,7 @@ module RuboCop
|
|
149
149
|
end
|
150
150
|
|
151
151
|
def filename_ends_with?(pattern)
|
152
|
-
|
153
|
-
filename.match?("#{pattern}$")
|
152
|
+
expanded_file_path.match?("#{pattern}$")
|
154
153
|
end
|
155
154
|
|
156
155
|
def relevant_rubocop_rspec_file?(_file)
|
@@ -160,6 +159,14 @@ module RuboCop
|
|
160
159
|
def spec_suffix_only?
|
161
160
|
cop_config['SpecSuffixOnly']
|
162
161
|
end
|
162
|
+
|
163
|
+
def routing_spec_path?
|
164
|
+
expanded_file_path.include?('spec/routing/')
|
165
|
+
end
|
166
|
+
|
167
|
+
def expanded_file_path
|
168
|
+
File.expand_path(processed_source.buffer.name)
|
169
|
+
end
|
163
170
|
end
|
164
171
|
end
|
165
172
|
end
|
@@ -89,11 +89,21 @@ module RuboCop
|
|
89
89
|
# @param [RuboCop::AST::Corrector] corrector
|
90
90
|
# @param [RuboCop::AST::Node] node
|
91
91
|
def autocorrect(corrector, node)
|
92
|
-
corrector.remove(
|
93
|
-
|
94
|
-
|
92
|
+
corrector.remove(remove_range(node))
|
93
|
+
end
|
94
|
+
|
95
|
+
# @param [RuboCop::AST::Node] node
|
96
|
+
# @return [Parser::Source::Range]
|
97
|
+
def remove_range(node)
|
98
|
+
if node.left_sibling
|
99
|
+
node.loc.expression.with(
|
100
|
+
begin_pos: node.left_sibling.loc.expression.end_pos
|
95
101
|
)
|
96
|
-
|
102
|
+
elsif node.right_sibling
|
103
|
+
node.loc.expression.with(
|
104
|
+
end_pos: node.right_sibling.loc.expression.begin_pos
|
105
|
+
)
|
106
|
+
end
|
97
107
|
end
|
98
108
|
|
99
109
|
# @param [RuboCop::AST::PairNode] node
|
@@ -26,8 +26,7 @@ module RuboCop
|
|
26
26
|
def_node_matcher :rspec_metadata, <<~PATTERN
|
27
27
|
(block
|
28
28
|
(send
|
29
|
-
#rspec? {#Examples.all #ExampleGroups.all #SharedGroups.all #Hooks.all
|
30
|
-
_ ${send str sym}* (hash $...)?)
|
29
|
+
#rspec? {#Examples.all #ExampleGroups.all #SharedGroups.all #Hooks.all} _ ${send str sym}* (hash $...)?)
|
31
30
|
...)
|
32
31
|
PATTERN
|
33
32
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.14.
|
4
|
+
version: 2.14.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Backus
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2022-10-
|
13
|
+
date: 2022-10-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|