rubocop-rspec 2.28.0 → 2.29.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: 3bec4edcf5bcf8c729a8c897b3de5b80b68c08de7ee3b2a25cfa23518db43390
4
- data.tar.gz: '0848c7f26310108d511c7986127016963432371d6554c679a8fb318387c05998'
3
+ metadata.gz: 17925b2c404825ce202d012a1b5176358a7328cbdf5c956426b2be463c07707a
4
+ data.tar.gz: bf216b0348237ccb7020b7dad2cb79c700c46f7bdbc85bdf65c5a2740aea12e8
5
5
  SHA512:
6
- metadata.gz: 72958ac870b50c4b3c5b91be2f18ab88d6b2abf64af255e56451c0a6f58b3fd570dd2a3452e7326af58af57cce9347e370978bd21685f6470bba50ea8d93b195
7
- data.tar.gz: 34dc88c068186ac780e2c3e4ebc3048159c236acc4b685fd6630cd59de0910a3f4f181a310d0e2ff7d1b5f9a2609219118119ff23dee212b870b24f685aef195
6
+ metadata.gz: fb4265f89166d4df1e75b2eef2a2b3d709e93834511dde371765cf21d0efb7af158bc2a165b98dc0106ffb979003b2d924543074c00268445df924a6d3ec8cc0
7
+ data.tar.gz: 90fc7033f83e79d3aa77eab277247ce0c6b66b20db115d24834ed28940f584c656eb6588f93250e1abea901ad4b83cac012d0339e64b4a5633b48abed9c4b568
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## Master (Unreleased)
4
4
 
5
+ ## 2.29.0 (2024-04-04)
6
+
7
+ - Fix an autocorrect error for `RSpec/ExpectActual`. ([@bquorning])
8
+ - Add new `RSpec/UndescriptiveLiteralsDescription` cop. ([@ydah])
9
+ - Add new `RSpec/EmptyOutput` cop. ([@bquorning])
10
+
5
11
  ## 2.28.0 (2024-03-30)
6
12
 
7
13
  - Extract RSpec Rails cops to a separate repository, [`rubocop-rspec_rails`](https://github.com/rubocop/rubocop-rspec_rails). The `rubocop-rspec_rails` repository is a dependency of `rubocop-rspec` and the cops related to rspec-rails are aliased (`RSpec/Rails/Foo` == `RSpecRails/Foo`) until v3.0 is released, so the change will be invisible to users until then. ([@ydah])
data/config/default.yml CHANGED
@@ -366,6 +366,12 @@ RSpec/EmptyMetadata:
366
366
  VersionAdded: '2.24'
367
367
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyMetadata
368
368
 
369
+ RSpec/EmptyOutput:
370
+ Description: Check that the `output` matcher is not called with an empty string.
371
+ Enabled: pending
372
+ VersionAdded: "<<next>>"
373
+ Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyOutput
374
+
369
375
  RSpec/Eq:
370
376
  Description: Use `eq` instead of `be ==` to compare objects.
371
377
  Enabled: pending
@@ -932,6 +938,12 @@ RSpec/SubjectStub:
932
938
  StyleGuide: https://rspec.rubystyle.guide/#dont-stub-subject
933
939
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SubjectStub
934
940
 
941
+ RSpec/UndescriptiveLiteralsDescription:
942
+ Description: Description should be descriptive.
943
+ Enabled: pending
944
+ VersionAdded: '2.29'
945
+ Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/UndescriptiveLiteralsDescription
946
+
935
947
  RSpec/UnspecifiedException:
936
948
  Description: Checks for a specified error in checking raised errors.
937
949
  Enabled: true
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module RSpec
6
- # Checks for empty before and after hooks.
6
+ # Checks for empty before and after hooks.
7
7
  #
8
8
  # @example
9
9
  # # bad
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module RSpec
6
+ # Check that the `output` matcher is not called with an empty string.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # expect { foo }.to output('').to_stdout
11
+ # expect { bar }.not_to output('').to_stderr
12
+ #
13
+ # # good
14
+ # expect { foo }.not_to output.to_stdout
15
+ # expect { bar }.to output.to_stderr
16
+ #
17
+ class EmptyOutput < Base
18
+ extend AutoCorrector
19
+
20
+ MSG = 'Use `%<runner>s` instead of matching on an empty output.'
21
+ RESTRICT_ON_SEND = Runners.all
22
+
23
+ # @!method matching_empty_output(node)
24
+ def_node_matcher :matching_empty_output, <<~PATTERN
25
+ (send
26
+ (block
27
+ (send nil? :expect) ...
28
+ )
29
+ #Runners.all
30
+ (send $(send nil? :output (str empty?)) ...)
31
+ )
32
+ PATTERN
33
+
34
+ def on_send(send_node)
35
+ matching_empty_output(send_node) do |node|
36
+ runner = send_node.method?(:to) ? 'not_to' : 'to'
37
+ message = format(MSG, runner: runner)
38
+ add_offense(node, message: message) do |corrector|
39
+ corrector.replace(send_node.loc.selector, runner)
40
+ corrector.replace(node, 'output')
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -58,22 +58,27 @@ module RuboCop
58
58
  (send
59
59
  (send nil? :expect $#literal?)
60
60
  #Runners.all
61
- {
61
+ ${
62
62
  (send (send nil? $:be) :== $_)
63
63
  (send nil? $_ $_ ...)
64
64
  }
65
65
  )
66
66
  PATTERN
67
67
 
68
- def on_send(node)
69
- expect_literal(node) do |actual, matcher, expected|
68
+ def on_send(node) # rubocop:disable Metrics/MethodLength
69
+ expect_literal(node) do |actual, send_node, matcher, expected|
70
70
  next if SKIPPED_MATCHERS.include?(matcher)
71
71
 
72
72
  add_offense(actual.source_range) do |corrector|
73
73
  next unless CORRECTABLE_MATCHERS.include?(matcher)
74
74
  next if literal?(expected)
75
75
 
76
- swap(corrector, actual, expected)
76
+ corrector.replace(actual, expected.source)
77
+ if matcher == :be
78
+ corrector.replace(expected, actual.source)
79
+ else
80
+ corrector.replace(send_node, "#{matcher}(#{actual.source})")
81
+ end
77
82
  end
78
83
  end
79
84
  end
@@ -94,11 +99,6 @@ module RuboCop
94
99
  COMPLEX_LITERALS.include?(node.type) &&
95
100
  node.each_child_node.all?(&method(:literal?))
96
101
  end
97
-
98
- def swap(corrector, actual, expected)
99
- corrector.replace(actual, expected.source)
100
- corrector.replace(expected, actual.source)
101
- end
102
102
  end
103
103
  end
104
104
  end
@@ -31,7 +31,7 @@ module RuboCop
31
31
  # end
32
32
  #
33
33
  # @example `aggregate_failures: true` (default)
34
- # # good - the cop ignores when RSpec aggregates failures
34
+ # # good - the cop ignores when RSpec aggregates failures
35
35
  # describe UserCreator do
36
36
  # it 'builds a user', :aggregate_failures do
37
37
  # expect(user.name).to eq("John")
@@ -40,7 +40,7 @@ module RuboCop
40
40
  # end
41
41
  #
42
42
  # @example `aggregate_failures: false`
43
- # # Detected as an offense
43
+ # # Detected as an offense
44
44
  # describe UserCreator do
45
45
  # it 'builds a user', aggregate_failures: false do
46
46
  # expect(user.name).to eq("John")
@@ -19,7 +19,7 @@ module RuboCop
19
19
  # # allow(foo).to receive(:bar)
20
20
  # # end
21
21
  # #
22
- # class AvoidSetupHook < RuboCop::Cop::RSpecRails::Base; end
22
+ # class AvoidSetupHook < RuboCop::Cop::RSpec::Base; end
23
23
  AvoidSetupHook = ::RuboCop::Cop::RSpecRails::AvoidSetupHook
24
24
  end
25
25
  end
@@ -53,7 +53,7 @@ module RuboCop
53
53
  # # it { is_expected.to have_http_status :success }
54
54
  # # it { is_expected.to have_http_status :error }
55
55
  # #
56
- # class HttpStatus < RuboCop::Cop::RSpecRails::Base; end
56
+ # class HttpStatus < RuboCop::Cop::RSpec::Base; end
57
57
  HttpStatus = ::RuboCop::Cop::RSpecRails::HttpStatus
58
58
  end
59
59
  end
@@ -54,7 +54,7 @@ module RuboCop
54
54
  # # RSpec.describe User, type: :common do
55
55
  # # end
56
56
  # #
57
- # class InferredSpecType < RuboCop::Cop::RSpecRails::Base; end
57
+ # class InferredSpecType < RuboCop::Cop::RSpec::Base; end
58
58
  InferredSpecType = ::RuboCop::Cop::RSpecRails::InferredSpecType
59
59
  end
60
60
  end
@@ -31,7 +31,7 @@ module RuboCop
31
31
  # # expect(a).to be(true)
32
32
  # # expect(a).to be(false)
33
33
  # #
34
- # class MinitestAssertions < RuboCop::Cop::RSpecRails::Base; end
34
+ # class MinitestAssertions < RuboCop::Cop::RSpec::Base; end
35
35
  MinitestAssertions = ::RuboCop::Cop::RSpecRails::MinitestAssertions
36
36
  end
37
37
  end
@@ -31,7 +31,7 @@ module RuboCop
31
31
  # # # good (with method chain)
32
32
  # # expect(foo).to be_invalid.or be_even
33
33
  # #
34
- # class NegationBeValid < RuboCop::Cop::RSpecRails::Base; end
34
+ # class NegationBeValid < RuboCop::Cop::RSpec::Base; end
35
35
  NegationBeValid = ::RuboCop::Cop::RSpecRails::NegationBeValid
36
36
  end
37
37
  end
@@ -26,7 +26,7 @@ module RuboCop
26
26
  # # # good
27
27
  # # before { freeze_time }
28
28
  # #
29
- # class TravelAround < RuboCop::Cop::RSpecRails::Base; end
29
+ # class TravelAround < RuboCop::Cop::RSpec::Base; end
30
30
  TravelAround = ::RuboCop::Cop::RSpecRails::TravelAround
31
31
  end
32
32
  end
@@ -7,13 +7,13 @@ module RuboCop
7
7
  #
8
8
  # @example
9
9
  #
10
- # it 'is valid' do
11
- # expect(user).to be_valid
12
- # end
10
+ # it 'is valid' do
11
+ # expect(user).to be_valid
12
+ # end
13
13
  #
14
- # it 'validates the user' do
15
- # expect(user).to be_valid
16
- # end
14
+ # it 'validates the user' do
15
+ # expect(user).to be_valid
16
+ # end
17
17
  #
18
18
  class RepeatedExample < Base
19
19
  MSG = "Don't repeat examples within an example group."
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module RSpec
6
+ # Description should be descriptive.
7
+ #
8
+ # If example group or example contains only `execute string`, numbers
9
+ # and regular expressions, the description is not clear.
10
+ #
11
+ # @example
12
+ # # bad
13
+ # describe `time` do
14
+ # # ...
15
+ # end
16
+ #
17
+ # # bad
18
+ # context /when foo/ do
19
+ # # ...
20
+ # end
21
+ #
22
+ # # bad
23
+ # it 10000 do
24
+ # # ...
25
+ # end
26
+ #
27
+ # # good
28
+ # describe Foo do
29
+ # # ...
30
+ # end
31
+ #
32
+ # # good
33
+ # describe '#foo' do
34
+ # # ...
35
+ # end
36
+ #
37
+ # # good
38
+ # context "when #{foo} is bar" do
39
+ # # ...
40
+ # end
41
+ #
42
+ # # good
43
+ # it 'does something' do
44
+ # # ...
45
+ # end
46
+ #
47
+ class UndescriptiveLiteralsDescription < Base
48
+ MSG = 'Description should be descriptive.'
49
+
50
+ # @!method example_groups_or_example?(node)
51
+ def_node_matcher :example_groups_or_example?, <<~PATTERN
52
+ (block (send #rspec? {#ExampleGroups.all #Examples.all} $_) ...)
53
+ PATTERN
54
+
55
+ def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
56
+ example_groups_or_example?(node) do |arg|
57
+ add_offense(arg) if offense?(arg)
58
+ end
59
+ end
60
+
61
+ private
62
+
63
+ def offense?(node)
64
+ %i[xstr int regexp].include?(node.type)
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -54,6 +54,7 @@ require_relative 'rspec/empty_line_after_final_let'
54
54
  require_relative 'rspec/empty_line_after_hook'
55
55
  require_relative 'rspec/empty_line_after_subject'
56
56
  require_relative 'rspec/empty_metadata'
57
+ require_relative 'rspec/empty_output'
57
58
  require_relative 'rspec/eq'
58
59
  require_relative 'rspec/example_length'
59
60
  require_relative 'rspec/example_without_description'
@@ -124,6 +125,7 @@ require_relative 'rspec/spec_file_path_suffix'
124
125
  require_relative 'rspec/stubbed_mock'
125
126
  require_relative 'rspec/subject_declaration'
126
127
  require_relative 'rspec/subject_stub'
128
+ require_relative 'rspec/undescriptive_literals_description'
127
129
  require_relative 'rspec/unspecified_exception'
128
130
  require_relative 'rspec/variable_definition'
129
131
  require_relative 'rspec/variable_name'
@@ -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.28.0'
7
+ STRING = '2.29.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.28.0
4
+ version: 2.29.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: 2024-03-29 00:00:00.000000000 Z
13
+ date: 2024-04-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop
@@ -127,6 +127,7 @@ files:
127
127
  - lib/rubocop/cop/rspec/empty_line_after_hook.rb
128
128
  - lib/rubocop/cop/rspec/empty_line_after_subject.rb
129
129
  - lib/rubocop/cop/rspec/empty_metadata.rb
130
+ - lib/rubocop/cop/rspec/empty_output.rb
130
131
  - lib/rubocop/cop/rspec/eq.rb
131
132
  - lib/rubocop/cop/rspec/example_length.rb
132
133
  - lib/rubocop/cop/rspec/example_without_description.rb
@@ -221,6 +222,7 @@ files:
221
222
  - lib/rubocop/cop/rspec/stubbed_mock.rb
222
223
  - lib/rubocop/cop/rspec/subject_declaration.rb
223
224
  - lib/rubocop/cop/rspec/subject_stub.rb
225
+ - lib/rubocop/cop/rspec/undescriptive_literals_description.rb
224
226
  - lib/rubocop/cop/rspec/unspecified_exception.rb
225
227
  - lib/rubocop/cop/rspec/variable_definition.rb
226
228
  - lib/rubocop/cop/rspec/variable_name.rb
@@ -252,7 +254,7 @@ metadata:
252
254
  changelog_uri: https://github.com/rubocop/rubocop-rspec/blob/master/CHANGELOG.md
253
255
  documentation_uri: https://docs.rubocop.org/rubocop-rspec/
254
256
  rubygems_mfa_required: 'true'
255
- post_install_message:
257
+ post_install_message:
256
258
  rdoc_options: []
257
259
  require_paths:
258
260
  - lib
@@ -267,8 +269,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
267
269
  - !ruby/object:Gem::Version
268
270
  version: '0'
269
271
  requirements: []
270
- rubygems_version: 3.5.7
271
- signing_key:
272
+ rubygems_version: 3.5.3
273
+ signing_key:
272
274
  specification_version: 4
273
275
  summary: Code style checking for RSpec files
274
276
  test_files: []