rubocop-rspec 2.4.0 → 2.5.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: 35d3cf723ee0c50db00cbc5e63f5d9bf142186843fd56a86248dfb284c65180c
4
- data.tar.gz: 8d0c0e01c405332eac2075b60d518a71e82a7d54f4b41ef111f5ef2b869e1f88
3
+ metadata.gz: 22b3b217241494fa4c167f2e15e07a19d360d5807d0278d58b0a5504c9268b8d
4
+ data.tar.gz: 9111683fcaefd7c78675ce0549fa7e2a6a0c06a1b41e99b98472bd92b7459d03
5
5
  SHA512:
6
- metadata.gz: 2e28be09b6cc11154b903ef574ef44487c44ade441f79b1172569d66cecd2c027d525dbcefbe755d7a0f2c872491a018fb24cd026453dc13ac764bcae7312abc
7
- data.tar.gz: 3062cea8205acc5e020c404034c8c2590c6c5c089649c62280887b0bc20ca3b4b38048a983b2947f9ed10bc1824992955c6a58736db53f071c72a3fdde9363f8
6
+ metadata.gz: 4276ab19bc2cbaad8649d0380b77be083d3afb21397ea63614b1a6275fc47b615c1f418d3ebbdf44e4bd674d3d663c896d74863798a1c2b208d06d5ac248e777
7
+ data.tar.gz: 0b95a2233468bd4cd06596fe0a7c37d1f36e9481815cda16aa287eb8d479274e0aac813ceb2eede688853506fb023e7e469292713e4288271049573536ccbe94
data/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  ## Master (Unreleased)
4
4
 
5
+ ## 2.5.0 (2021-09-21)
6
+
7
+ * Declare autocorrect as unsafe for `ExpectChange`. ([@francois-ferrandis][])
8
+ * Fix each example for `RSpec/HookArgument`. ([@lokhi][])
9
+ * Exclude unrelated Rails directories from `RSpec/DescribeClass`. ([@MothOnMars][])
10
+ * Add `RSpec/ExcessiveDocstringSpacing` cop. ([@G-Rath][])
11
+ * Add `RSpec/SubjectDeclaration` cop. ([@dswij][])
12
+ * Fix excessive whitespace removal in `RSpec/EmptyHook` autocorrection. ([@pirj][])
13
+ * Bump RuboCop requirement to v1.19.0. ([@pirj][])
14
+ * Fix false positive in `RSpec/IteratedExpectation` when there is single, non-expectation statement in the block body. ([@Darhazer][])
15
+
5
16
  ## 2.4.0 (2021-06-09)
6
17
 
7
18
  * Update `RSpec/FilePath` to check suffix when given a non-constant top-level node (e.g. features). ([@topalovic][])
@@ -625,3 +636,8 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
625
636
  [@rrosenblum]: https://github.com/rrosenblum
626
637
  [@paydaylight]: https://github.com/paydaylight
627
638
  [@topalovic]: https://github.com/topalovic
639
+ [@lokhi]: https://github.com/lokhi
640
+ [@MothOnMars]: https://github.com/MothOnMars
641
+ [@G-Rath]: https://github.com/G-Rath
642
+ [@dswij]: https://github.com/dswij
643
+ [@francois-ferrandis]: https://github.com/francois-ferrandis
data/config/default.yml CHANGED
@@ -148,6 +148,12 @@ RSpec/ContextWording:
148
148
  RSpec/DescribeClass:
149
149
  Description: Check that the first argument to the top-level describe is a constant.
150
150
  Enabled: true
151
+ Exclude:
152
+ - "**/spec/features/**/*"
153
+ - "**/spec/requests/**/*"
154
+ - "**/spec/routing/**/*"
155
+ - "**/spec/system/**/*"
156
+ - "**/spec/views/**/*"
151
157
  IgnoredMetadata:
152
158
  type:
153
159
  - channel
@@ -164,7 +170,7 @@ RSpec/DescribeClass:
164
170
  - mailbox
165
171
  - aruba
166
172
  VersionAdded: '1.0'
167
- VersionChanged: '1.44'
173
+ VersionChanged: '2.5'
168
174
  StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribeClass
169
175
 
170
176
  RSpec/DescribeMethod:
@@ -269,6 +275,12 @@ RSpec/ExampleWithoutDescription:
269
275
  VersionAdded: '1.22'
270
276
  StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExampleWithoutDescription
271
277
 
278
+ RSpec/ExcessiveDocstringSpacing:
279
+ Description: Checks for excessive whitespace in example descriptions.
280
+ Enabled: pending
281
+ VersionAdded: '2.5'
282
+ StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExcessiveDocstringSpacing
283
+
272
284
  RSpec/ExampleWording:
273
285
  Description: Checks for common mistakes in example descriptions.
274
286
  Enabled: true
@@ -297,7 +309,9 @@ RSpec/ExpectChange:
297
309
  SupportedStyles:
298
310
  - method_call
299
311
  - block
312
+ SafeAutoCorrect: false
300
313
  VersionAdded: '1.22'
314
+ VersionChanged: '2.5'
301
315
  StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExpectChange
302
316
 
303
317
  RSpec/ExpectInHook:
@@ -643,6 +657,12 @@ RSpec/StubbedMock:
643
657
  VersionAdded: '1.44'
644
658
  StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/StubbedMock
645
659
 
660
+ RSpec/SubjectDeclaration:
661
+ Description: Ensure that subject is defined using subject helper.
662
+ Enabled: pending
663
+ VersionAdded: '2.5'
664
+ StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SubjectDeclaration
665
+
646
666
  RSpec/SubjectStub:
647
667
  Description: Checks for stubbed test subjects.
648
668
  Enabled: true
@@ -36,7 +36,10 @@ module RuboCop
36
36
  def on_block(node)
37
37
  empty_hook?(node) do |hook|
38
38
  add_offense(hook) do |corrector|
39
- range = range_with_surrounding_space(range: node.loc.expression)
39
+ range = range_with_surrounding_space(
40
+ range: node.loc.expression,
41
+ side: :left
42
+ )
40
43
  corrector.remove(range)
41
44
  end
42
45
  end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module RSpec
6
+ # Checks for excessive whitespace in example descriptions.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # it ' has excessive spacing ' do
11
+ # end
12
+ #
13
+ # # good
14
+ # it 'has excessive spacing' do
15
+ # end
16
+ #
17
+ # @example
18
+ # # bad
19
+ # context ' when a condition is met ' do
20
+ # end
21
+ #
22
+ # # good
23
+ # context 'when a condition is met' do
24
+ # end
25
+ class ExcessiveDocstringSpacing < Base
26
+ extend AutoCorrector
27
+
28
+ MSG = 'Excessive whitespace.'
29
+
30
+ # @!method example_description(node)
31
+ def_node_matcher :example_description, <<-PATTERN
32
+ (send _ {#Examples.all #ExampleGroups.all} ${
33
+ $str
34
+ $(dstr ({str dstr `sym} ...) ...)
35
+ } ...)
36
+ PATTERN
37
+
38
+ def on_send(node)
39
+ example_description(node) do |description_node, message|
40
+ text = text(message)
41
+
42
+ return unless excessive_whitespace?(text)
43
+
44
+ add_whitespace_offense(description_node, text)
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ # @param text [String]
51
+ def excessive_whitespace?(text)
52
+ text.start_with?(' ') || text.include?(' ') || text.end_with?(' ')
53
+ end
54
+
55
+ # @param text [String]
56
+ def strip_excessive_whitespace(text)
57
+ text.strip.gsub(/ +/, ' ')
58
+ end
59
+
60
+ # @param node [RuboCop::AST::Node]
61
+ # @param text [String]
62
+ def add_whitespace_offense(node, text)
63
+ docstring = docstring(node)
64
+ corrected = strip_excessive_whitespace(text)
65
+
66
+ add_offense(docstring) do |corrector|
67
+ corrector.replace(docstring, corrected)
68
+ end
69
+ end
70
+
71
+ def docstring(node)
72
+ expr = node.loc.expression
73
+
74
+ Parser::Source::Range.new(
75
+ expr.source_buffer,
76
+ expr.begin_pos + 1,
77
+ expr.end_pos - 1
78
+ )
79
+ end
80
+
81
+ # Recursive processing is required to process nested dstr nodes
82
+ # that is the case for \-separated multiline strings with interpolation.
83
+ def text(node)
84
+ case node.type
85
+ when :dstr
86
+ node.node_parts.map { |child_node| text(child_node) }.join
87
+ when :str, :sym
88
+ node.value
89
+ when :begin
90
+ node.source
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -32,7 +32,7 @@ module RuboCop
32
32
  # # ...
33
33
  # end
34
34
  #
35
- # # good
35
+ # # bad
36
36
  # before do
37
37
  # # ...
38
38
  # end
@@ -48,6 +48,8 @@ module RuboCop
48
48
  end
49
49
 
50
50
  def only_expectations?(body, arg)
51
+ return false unless body.each_child_node.any?
52
+
51
53
  body.each_child_node.all? { |child| expectation?(child, arg) }
52
54
  end
53
55
  end
@@ -6,7 +6,7 @@ module RuboCop
6
6
  # Checks for nested example groups.
7
7
  #
8
8
  # This cop is configurable using the `Max` option
9
- # and supports `--auto-gen-config
9
+ # and supports `--auto-gen-config`.
10
10
  #
11
11
  # @example
12
12
  # # bad
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module RSpec
6
+ # Ensure that subject is defined using subject helper.
7
+ #
8
+ # @example
9
+ #
10
+ # # bad
11
+ # let(:subject) { foo }
12
+ # let!(:subject) { foo }
13
+ # subject(:subject) { foo }
14
+ # subject!(:subject) { foo }
15
+ #
16
+ # # bad
17
+ # block = -> {}
18
+ # let(:subject, &block)
19
+ #
20
+ # # good
21
+ # subject(:test_subject) { foo }
22
+ #
23
+ class SubjectDeclaration < Base
24
+ MSG_LET = 'Use subject explicitly rather than using let'
25
+ MSG_REDUNDANT = 'Ambiguous declaration of subject'
26
+
27
+ # @!method offensive_subject_declaration?(node)
28
+ def_node_matcher :offensive_subject_declaration?, <<~PATTERN
29
+ (send nil? ${#Subjects.all #Helpers.all} {(sym :subject) (str "subject")} ...)
30
+ PATTERN
31
+
32
+ def on_send(node)
33
+ offense = offensive_subject_declaration?(node)
34
+ return unless offense
35
+
36
+ add_offense(node, message: message_for(offense))
37
+ end
38
+
39
+ private
40
+
41
+ def message_for(offense)
42
+ Helpers.all(offense) ? MSG_LET : MSG_REDUNDANT
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -40,6 +40,7 @@ require_relative 'rspec/empty_line_after_subject'
40
40
  require_relative 'rspec/example_length'
41
41
  require_relative 'rspec/example_without_description'
42
42
  require_relative 'rspec/example_wording'
43
+ require_relative 'rspec/excessive_docstring_spacing'
43
44
  require_relative 'rspec/expect_actual'
44
45
  require_relative 'rspec/expect_change'
45
46
  require_relative 'rspec/expect_in_hook'
@@ -88,6 +89,7 @@ require_relative 'rspec/shared_context'
88
89
  require_relative 'rspec/shared_examples'
89
90
  require_relative 'rspec/single_argument_message_chain'
90
91
  require_relative 'rspec/stubbed_mock'
92
+ require_relative 'rspec/subject_declaration'
91
93
  require_relative 'rspec/subject_stub'
92
94
  require_relative 'rspec/unspecified_exception'
93
95
  require_relative 'rspec/variable_definition'
@@ -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.4.0'
7
+ STRING = '2.5.0'
8
8
  end
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Backus
8
8
  - Ian MacLeod
9
9
  - Nils Gemeinhardt
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-06-09 00:00:00.000000000 Z
13
+ date: 2021-09-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop
@@ -18,28 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: '1.0'
21
+ version: '1.19'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - "~>"
27
27
  - !ruby/object:Gem::Version
28
- version: '1.0'
29
- - !ruby/object:Gem::Dependency
30
- name: rubocop-ast
31
- requirement: !ruby/object:Gem::Requirement
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
35
- version: 1.1.0
36
- type: :runtime
37
- prerelease: false
38
- version_requirements: !ruby/object:Gem::Requirement
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- version: 1.1.0
28
+ version: '1.19'
43
29
  - !ruby/object:Gem::Dependency
44
30
  name: rack
45
31
  requirement: !ruby/object:Gem::Requirement
@@ -96,6 +82,20 @@ dependencies:
96
82
  - - "~>"
97
83
  - !ruby/object:Gem::Version
98
84
  version: '1.7'
85
+ - !ruby/object:Gem::Dependency
86
+ name: rubocop-rake
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '0.6'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - "~>"
97
+ - !ruby/object:Gem::Version
98
+ version: '0.6'
99
99
  - !ruby/object:Gem::Dependency
100
100
  name: simplecov
101
101
  requirement: !ruby/object:Gem::Requirement
@@ -172,6 +172,7 @@ files:
172
172
  - lib/rubocop/cop/rspec/example_length.rb
173
173
  - lib/rubocop/cop/rspec/example_without_description.rb
174
174
  - lib/rubocop/cop/rspec/example_wording.rb
175
+ - lib/rubocop/cop/rspec/excessive_docstring_spacing.rb
175
176
  - lib/rubocop/cop/rspec/expect_actual.rb
176
177
  - lib/rubocop/cop/rspec/expect_change.rb
177
178
  - lib/rubocop/cop/rspec/expect_in_hook.rb
@@ -230,6 +231,7 @@ files:
230
231
  - lib/rubocop/cop/rspec/shared_examples.rb
231
232
  - lib/rubocop/cop/rspec/single_argument_message_chain.rb
232
233
  - lib/rubocop/cop/rspec/stubbed_mock.rb
234
+ - lib/rubocop/cop/rspec/subject_declaration.rb
233
235
  - lib/rubocop/cop/rspec/subject_stub.rb
234
236
  - lib/rubocop/cop/rspec/unspecified_exception.rb
235
237
  - lib/rubocop/cop/rspec/variable_definition.rb
@@ -259,7 +261,7 @@ licenses:
259
261
  metadata:
260
262
  changelog_uri: https://github.com/rubocop/rubocop-rspec/blob/master/CHANGELOG.md
261
263
  documentation_uri: https://docs.rubocop.org/rubocop-rspec/
262
- post_install_message:
264
+ post_install_message:
263
265
  rdoc_options: []
264
266
  require_paths:
265
267
  - lib
@@ -274,8 +276,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
274
276
  - !ruby/object:Gem::Version
275
277
  version: '0'
276
278
  requirements: []
277
- rubygems_version: 3.2.16
278
- signing_key:
279
+ rubygems_version: 3.1.2
280
+ signing_key:
279
281
  specification_version: 4
280
282
  summary: Code style checking for RSpec files
281
283
  test_files: []