rubocop-rspec 2.27.1 → 2.29.0
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 +4 -4
- data/CHANGELOG.md +10 -0
- data/config/default.yml +12 -0
- data/config/obsoletion.yml +7 -0
- data/lib/rubocop/cop/rspec/empty_hook.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_output.rb +47 -0
- data/lib/rubocop/cop/rspec/expect_actual.rb +9 -9
- data/lib/rubocop/cop/rspec/instance_variable.rb +1 -1
- data/lib/rubocop/cop/rspec/multiple_expectations.rb +2 -2
- data/lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb +17 -33
- data/lib/rubocop/cop/rspec/rails/have_http_status.rb +25 -69
- data/lib/rubocop/cop/rspec/rails/http_status.rb +51 -204
- data/lib/rubocop/cop/rspec/rails/inferred_spec_type.rb +52 -135
- data/lib/rubocop/cop/rspec/rails/minitest_assertions.rb +29 -342
- data/lib/rubocop/cop/rspec/rails/negation_be_valid.rb +29 -92
- data/lib/rubocop/cop/rspec/rails/travel_around.rb +24 -82
- data/lib/rubocop/cop/rspec/repeated_example.rb +6 -6
- data/lib/rubocop/cop/rspec/undescriptive_literals_description.rb +69 -0
- data/lib/rubocop/cop/rspec_cops.rb +4 -6
- data/lib/rubocop/rspec/config_formatter.rb +7 -0
- data/lib/rubocop/rspec/version.rb +1 -1
- data/lib/rubocop-rspec.rb +3 -0
- metadata +22 -6
@@ -4,98 +4,35 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module RSpec
|
6
6
|
module Rails
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# #
|
15
|
-
#
|
16
|
-
#
|
17
|
-
# #
|
18
|
-
#
|
19
|
-
#
|
20
|
-
# #
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
# #
|
25
|
-
#
|
26
|
-
#
|
27
|
-
# #
|
28
|
-
#
|
29
|
-
#
|
30
|
-
# #
|
31
|
-
#
|
32
|
-
#
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
MSG = 'Use `expect(...).%<runner>s %<matcher>s`.'
|
38
|
-
RESTRICT_ON_SEND = %i[be_valid be_invalid].freeze
|
39
|
-
|
40
|
-
# @!method not_to?(node)
|
41
|
-
def_node_matcher :not_to?, <<~PATTERN
|
42
|
-
(send ... :not_to (send nil? :be_valid ...))
|
43
|
-
PATTERN
|
44
|
-
|
45
|
-
# @!method be_invalid?(node)
|
46
|
-
def_node_matcher :be_invalid?, <<~PATTERN
|
47
|
-
(send ... :to (send nil? :be_invalid ...))
|
48
|
-
PATTERN
|
49
|
-
|
50
|
-
def on_send(node)
|
51
|
-
return unless offense?(node.parent)
|
52
|
-
|
53
|
-
add_offense(offense_range(node),
|
54
|
-
message: message(node.method_name)) do |corrector|
|
55
|
-
corrector.replace(node.parent.loc.selector, replaced_runner)
|
56
|
-
corrector.replace(node.loc.selector, replaced_matcher)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
private
|
61
|
-
|
62
|
-
def offense?(node)
|
63
|
-
case style
|
64
|
-
when :not_to
|
65
|
-
be_invalid?(node)
|
66
|
-
when :be_invalid
|
67
|
-
not_to?(node)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def offense_range(node)
|
72
|
-
node.parent.loc.selector.with(end_pos: node.loc.selector.end_pos)
|
73
|
-
end
|
74
|
-
|
75
|
-
def message(_matcher)
|
76
|
-
format(MSG,
|
77
|
-
runner: replaced_runner,
|
78
|
-
matcher: replaced_matcher)
|
79
|
-
end
|
80
|
-
|
81
|
-
def replaced_runner
|
82
|
-
case style
|
83
|
-
when :not_to
|
84
|
-
'not_to'
|
85
|
-
when :be_invalid
|
86
|
-
'to'
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def replaced_matcher
|
91
|
-
case style
|
92
|
-
when :not_to
|
93
|
-
'be_valid'
|
94
|
-
when :be_invalid
|
95
|
-
'be_invalid'
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
7
|
+
# @!parse
|
8
|
+
# # Enforces use of `be_invalid` or `not_to` for negated be_valid.
|
9
|
+
# #
|
10
|
+
# # @safety
|
11
|
+
# # This cop is unsafe because it cannot guarantee that
|
12
|
+
# # the test target is an instance of `ActiveModel::Validations``.
|
13
|
+
# #
|
14
|
+
# # @example EnforcedStyle: not_to (default)
|
15
|
+
# # # bad
|
16
|
+
# # expect(foo).to be_invalid
|
17
|
+
# #
|
18
|
+
# # # good
|
19
|
+
# # expect(foo).not_to be_valid
|
20
|
+
# #
|
21
|
+
# # # good (with method chain)
|
22
|
+
# # expect(foo).to be_invalid.and be_odd
|
23
|
+
# #
|
24
|
+
# # @example EnforcedStyle: be_invalid
|
25
|
+
# # # bad
|
26
|
+
# # expect(foo).not_to be_valid
|
27
|
+
# #
|
28
|
+
# # # good
|
29
|
+
# # expect(foo).to be_invalid
|
30
|
+
# #
|
31
|
+
# # # good (with method chain)
|
32
|
+
# # expect(foo).to be_invalid.or be_even
|
33
|
+
# #
|
34
|
+
# class NegationBeValid < RuboCop::Cop::RSpec::Base; end
|
35
|
+
NegationBeValid = ::RuboCop::Cop::RSpecRails::NegationBeValid
|
99
36
|
end
|
100
37
|
end
|
101
38
|
end
|
@@ -4,88 +4,30 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module RSpec
|
6
6
|
module Rails
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
# #
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
# end
|
24
|
-
#
|
25
|
-
# #
|
26
|
-
#
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
TRAVEL_METHOD_NAMES = %i[
|
33
|
-
freeze_time
|
34
|
-
travel
|
35
|
-
travel_to
|
36
|
-
].to_set.freeze
|
37
|
-
|
38
|
-
# @!method extract_run_in_travel(node)
|
39
|
-
def_node_matcher :extract_run_in_travel, <<~PATTERN
|
40
|
-
(block
|
41
|
-
$(send nil? TRAVEL_METHOD_NAMES ...)
|
42
|
-
(args ...)
|
43
|
-
(send _ :run)
|
44
|
-
)
|
45
|
-
PATTERN
|
46
|
-
|
47
|
-
# @!method match_around_each?(node)
|
48
|
-
def_node_matcher :match_around_each?, <<~PATTERN
|
49
|
-
(block
|
50
|
-
(send _ :around (sym :each)?)
|
51
|
-
...
|
52
|
-
)
|
53
|
-
PATTERN
|
54
|
-
|
55
|
-
def on_block(node)
|
56
|
-
run_node = extract_run_in_travel(node)
|
57
|
-
return unless run_node
|
58
|
-
|
59
|
-
around_node = extract_surrounding_around_block(run_node)
|
60
|
-
return unless around_node
|
61
|
-
|
62
|
-
add_offense(node) do |corrector|
|
63
|
-
autocorrect(corrector, node, run_node, around_node)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
alias on_numblock on_block
|
67
|
-
|
68
|
-
private
|
69
|
-
|
70
|
-
def autocorrect(corrector, node, run_node, around_node)
|
71
|
-
corrector.replace(
|
72
|
-
node,
|
73
|
-
node.body.source
|
74
|
-
)
|
75
|
-
corrector.insert_before(
|
76
|
-
around_node,
|
77
|
-
"before { #{run_node.source} }\n\n"
|
78
|
-
)
|
79
|
-
end
|
80
|
-
|
81
|
-
# @param node [RuboCop::AST::BlockNode]
|
82
|
-
# @return [RuboCop::AST::BlockNode, nil]
|
83
|
-
def extract_surrounding_around_block(node)
|
84
|
-
node.each_ancestor(:block).find do |ancestor|
|
85
|
-
match_around_each?(ancestor)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
7
|
+
# @!parse
|
8
|
+
# # Prefer to travel in `before` rather than `around`.
|
9
|
+
# #
|
10
|
+
# # @safety
|
11
|
+
# # This cop is unsafe because the automatic `travel_back` is only
|
12
|
+
# # run on test cases that are considered as Rails related.
|
13
|
+
# #
|
14
|
+
# # And also, this cop's autocorrection is unsafe because the order
|
15
|
+
# # of execution will change if other steps exist before traveling
|
16
|
+
# # in `around`.
|
17
|
+
# #
|
18
|
+
# # @example
|
19
|
+
# # # bad
|
20
|
+
# # around do |example|
|
21
|
+
# # freeze_time do
|
22
|
+
# # example.run
|
23
|
+
# # end
|
24
|
+
# # end
|
25
|
+
# #
|
26
|
+
# # # good
|
27
|
+
# # before { freeze_time }
|
28
|
+
# #
|
29
|
+
# class TravelAround < RuboCop::Cop::RSpec::Base; end
|
30
|
+
TravelAround = ::RuboCop::Cop::RSpecRails::TravelAround
|
89
31
|
end
|
90
32
|
end
|
91
33
|
end
|
@@ -7,13 +7,13 @@ module RuboCop
|
|
7
7
|
#
|
8
8
|
# @example
|
9
9
|
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
10
|
+
# it 'is valid' do
|
11
|
+
# expect(user).to be_valid
|
12
|
+
# end
|
13
13
|
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
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
|
@@ -18,14 +18,10 @@ require_relative 'rspec/factory_bot/syntax_methods'
|
|
18
18
|
|
19
19
|
require_relative 'rspec/rails/avoid_setup_hook'
|
20
20
|
require_relative 'rspec/rails/have_http_status'
|
21
|
-
require_relative 'rspec/rails/
|
22
|
-
begin
|
23
|
-
require_relative 'rspec/rails/http_status'
|
24
|
-
rescue LoadError
|
25
|
-
# Rails/HttpStatus cannot be loaded if rack/utils is unavailable.
|
26
|
-
end
|
21
|
+
require_relative 'rspec/rails/http_status'
|
27
22
|
require_relative 'rspec/rails/inferred_spec_type'
|
28
23
|
require_relative 'rspec/rails/minitest_assertions'
|
24
|
+
require_relative 'rspec/rails/negation_be_valid'
|
29
25
|
require_relative 'rspec/rails/travel_around'
|
30
26
|
|
31
27
|
require_relative 'rspec/align_left_let_brace'
|
@@ -58,6 +54,7 @@ require_relative 'rspec/empty_line_after_final_let'
|
|
58
54
|
require_relative 'rspec/empty_line_after_hook'
|
59
55
|
require_relative 'rspec/empty_line_after_subject'
|
60
56
|
require_relative 'rspec/empty_metadata'
|
57
|
+
require_relative 'rspec/empty_output'
|
61
58
|
require_relative 'rspec/eq'
|
62
59
|
require_relative 'rspec/example_length'
|
63
60
|
require_relative 'rspec/example_without_description'
|
@@ -128,6 +125,7 @@ require_relative 'rspec/spec_file_path_suffix'
|
|
128
125
|
require_relative 'rspec/stubbed_mock'
|
129
126
|
require_relative 'rspec/subject_declaration'
|
130
127
|
require_relative 'rspec/subject_stub'
|
128
|
+
require_relative 'rspec/undescriptive_literals_description'
|
131
129
|
require_relative 'rspec/unspecified_exception'
|
132
130
|
require_relative 'rspec/variable_definition'
|
133
131
|
require_relative 'rspec/variable_name'
|
@@ -22,6 +22,13 @@ module RuboCop
|
|
22
22
|
RSpec/FactoryBot/FactoryClassName
|
23
23
|
RSpec/FactoryBot/FactoryNameStyle
|
24
24
|
RSpec/FactoryBot/SyntaxMethods
|
25
|
+
RSpec/Rails/AvoidSetupHook
|
26
|
+
RSpec/Rails/HaveHttpStatus
|
27
|
+
RSpec/Rails/HttpStatus
|
28
|
+
RSpec/Rails/InferredSpecType
|
29
|
+
RSpec/Rails/MinitestAssertions
|
30
|
+
RSpec/Rails/NegationBeValid
|
31
|
+
RSpec/Rails/TravelAround
|
25
32
|
)
|
26
33
|
AMENDMENTS = %(Metrics/BlockLength)
|
27
34
|
COP_DOC_BASE_URL = 'https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/'
|
data/lib/rubocop-rspec.rb
CHANGED
@@ -39,6 +39,9 @@ require_relative 'rubocop/rspec/example'
|
|
39
39
|
require_relative 'rubocop/rspec/example_group'
|
40
40
|
require_relative 'rubocop/rspec/hook'
|
41
41
|
|
42
|
+
# need after `require 'rubocop/cop/rspec/base'``
|
43
|
+
require 'rubocop-rspec_rails'
|
44
|
+
|
42
45
|
RuboCop::RSpec::Inject.defaults!
|
43
46
|
|
44
47
|
require_relative 'rubocop/cop/rspec_cops'
|
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
|
+
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-
|
13
|
+
date: 2024-04-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -54,6 +54,20 @@ dependencies:
|
|
54
54
|
- - "~>"
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: '2.22'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: rubocop-rspec_rails
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '2.28'
|
64
|
+
type: :runtime
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - "~>"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '2.28'
|
57
71
|
description: |
|
58
72
|
Code style checking for RSpec files.
|
59
73
|
A plugin for the RuboCop code style enforcing & linting tool.
|
@@ -113,6 +127,7 @@ files:
|
|
113
127
|
- lib/rubocop/cop/rspec/empty_line_after_hook.rb
|
114
128
|
- lib/rubocop/cop/rspec/empty_line_after_subject.rb
|
115
129
|
- lib/rubocop/cop/rspec/empty_metadata.rb
|
130
|
+
- lib/rubocop/cop/rspec/empty_output.rb
|
116
131
|
- lib/rubocop/cop/rspec/eq.rb
|
117
132
|
- lib/rubocop/cop/rspec/example_length.rb
|
118
133
|
- lib/rubocop/cop/rspec/example_without_description.rb
|
@@ -207,6 +222,7 @@ files:
|
|
207
222
|
- lib/rubocop/cop/rspec/stubbed_mock.rb
|
208
223
|
- lib/rubocop/cop/rspec/subject_declaration.rb
|
209
224
|
- lib/rubocop/cop/rspec/subject_stub.rb
|
225
|
+
- lib/rubocop/cop/rspec/undescriptive_literals_description.rb
|
210
226
|
- lib/rubocop/cop/rspec/unspecified_exception.rb
|
211
227
|
- lib/rubocop/cop/rspec/variable_definition.rb
|
212
228
|
- lib/rubocop/cop/rspec/variable_name.rb
|
@@ -238,7 +254,7 @@ metadata:
|
|
238
254
|
changelog_uri: https://github.com/rubocop/rubocop-rspec/blob/master/CHANGELOG.md
|
239
255
|
documentation_uri: https://docs.rubocop.org/rubocop-rspec/
|
240
256
|
rubygems_mfa_required: 'true'
|
241
|
-
post_install_message:
|
257
|
+
post_install_message:
|
242
258
|
rdoc_options: []
|
243
259
|
require_paths:
|
244
260
|
- lib
|
@@ -253,8 +269,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
253
269
|
- !ruby/object:Gem::Version
|
254
270
|
version: '0'
|
255
271
|
requirements: []
|
256
|
-
rubygems_version: 3.
|
257
|
-
signing_key:
|
272
|
+
rubygems_version: 3.5.3
|
273
|
+
signing_key:
|
258
274
|
specification_version: 4
|
259
275
|
summary: Code style checking for RSpec files
|
260
276
|
test_files: []
|