rubocop-rspec 2.14.0 → 2.14.2

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
2
  SHA256:
3
- metadata.gz: 6fdb82e2eec960744c6f4960acada2a37cb2fb1bc3a1159b2fc444795c11448e
4
- data.tar.gz: 8d5945bf3e9e839b84067fc38c68663b9b43394ee467421b152385cb5d0c111e
3
+ metadata.gz: bbd70ea9708a7d87e0a1307234e3ac5cc37cc6197e6b1cc72487342b772ec6f1
4
+ data.tar.gz: 0c50303e8a0d4218508c51e778d5cb6633b54fe6f823951ea5f8df68d162dfda
5
5
  SHA512:
6
- metadata.gz: 320019459649ac0cb26c13496564af8c5c442caaa3a9e2bbee7959954a8ee6fd17cfcd70d0031012197db01e6b32b38b27fe9ab634d0b69a771884753500a244
7
- data.tar.gz: cfa3023ab42ef3ce54160a11d5fcbdd02c6106ef52a631e2fd301b644b9659f0202224f03ac54061fe5135e8905c758b9ae4c790d1d527ff0fb28e020bda046a
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
- else
72
- check_and_handle_insufficient_examples(description_node)
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.first)
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, method_name)
104
- if spec_suffix_only? || !example_group.const_type?
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
- filename = File.expand_path(processed_source.buffer.name)
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
@@ -77,7 +77,7 @@ module RuboCop
77
77
  def_node_search :includes_expectation?, <<~PATTERN
78
78
  {
79
79
  #{send_pattern('#Expectations.all')}
80
- (send nil? `#matches_allowed_pattern?)
80
+ (send nil? `#matches_allowed_pattern? ...)
81
81
  }
82
82
  PATTERN
83
83
 
@@ -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
- node.location.expression.with(
94
- begin_pos: node.left_sibling.location.expression.end_pos
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 #Includes.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
 
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module RSpec
5
5
  # Version information for the RSpec RuboCop plugin.
6
6
  module Version
7
- STRING = '2.14.0'
7
+ STRING = '2.14.2'
8
8
  end
9
9
  end
10
10
  end
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.0
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-23 00:00:00.000000000 Z
13
+ date: 2022-10-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop