rubocop-rspec 2.4.0 → 2.8.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 +42 -0
- data/README.md +2 -4
- data/config/default.yml +187 -92
- data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +7 -7
- data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +2 -23
- data/lib/rubocop/cop/rspec/capybara/visibility_matcher.rb +3 -2
- data/lib/rubocop/cop/rspec/empty_hook.rb +4 -1
- data/lib/rubocop/cop/rspec/empty_line_after_subject.rb +3 -9
- data/lib/rubocop/cop/rspec/example_wording.rb +3 -0
- data/lib/rubocop/cop/rspec/excessive_docstring_spacing.rb +100 -0
- data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +4 -3
- data/lib/rubocop/cop/rspec/factory_bot/syntax_methods.rb +107 -0
- data/lib/rubocop/cop/rspec/hook_argument.rb +1 -1
- data/lib/rubocop/cop/rspec/iterated_expectation.rb +2 -0
- data/lib/rubocop/cop/rspec/leading_subject.rb +3 -7
- data/lib/rubocop/cop/rspec/mixin/inside_example_group.rb +29 -0
- data/lib/rubocop/cop/rspec/nested_groups.rb +1 -1
- data/lib/rubocop/cop/rspec/subject_declaration.rb +47 -0
- data/lib/rubocop/cop/rspec/subject_stub.rb +44 -18
- data/lib/rubocop/cop/rspec/variable_definition.rb +19 -2
- data/lib/rubocop/cop/rspec/yield.rb +1 -1
- data/lib/rubocop/cop/rspec_cops.rb +3 -0
- data/lib/rubocop/rspec/align_let_brace.rb +2 -1
- data/lib/rubocop/rspec/config_formatter.rb +6 -4
- data/lib/rubocop/rspec/factory_bot/language.rb +17 -0
- data/lib/rubocop/rspec/version.rb +1 -1
- data/lib/rubocop-rspec.rb +5 -2
- metadata +16 -24
@@ -23,6 +23,7 @@ module RuboCop
|
|
23
23
|
# subject('user') { create_user }
|
24
24
|
# let('user_name') { 'Adam' }
|
25
25
|
class VariableDefinition < Base
|
26
|
+
extend AutoCorrector
|
26
27
|
include ConfigurableEnforcedStyle
|
27
28
|
include Variable
|
28
29
|
|
@@ -30,14 +31,30 @@ module RuboCop
|
|
30
31
|
|
31
32
|
def on_send(node)
|
32
33
|
variable_definition?(node) do |variable|
|
33
|
-
|
34
|
-
|
34
|
+
next unless style_violation?(variable)
|
35
|
+
|
36
|
+
add_offense(
|
37
|
+
variable,
|
38
|
+
message: format(MSG, style: style)
|
39
|
+
) do |corrector|
|
40
|
+
corrector.replace(variable, correct_variable(variable))
|
35
41
|
end
|
36
42
|
end
|
37
43
|
end
|
38
44
|
|
39
45
|
private
|
40
46
|
|
47
|
+
def correct_variable(variable)
|
48
|
+
case variable.type
|
49
|
+
when :dsym
|
50
|
+
variable.source[1..-1]
|
51
|
+
when :sym
|
52
|
+
variable.value.to_s.inspect
|
53
|
+
else
|
54
|
+
variable.value.to_sym.inspect
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
41
58
|
def style_violation?(variable)
|
42
59
|
style == :symbols && string?(variable) ||
|
43
60
|
style == :strings && symbol?(variable)
|
@@ -7,6 +7,7 @@ require_relative 'rspec/capybara/visibility_matcher'
|
|
7
7
|
require_relative 'rspec/factory_bot/attribute_defined_statically'
|
8
8
|
require_relative 'rspec/factory_bot/create_list'
|
9
9
|
require_relative 'rspec/factory_bot/factory_class_name'
|
10
|
+
require_relative 'rspec/factory_bot/syntax_methods'
|
10
11
|
|
11
12
|
require_relative 'rspec/rails/avoid_setup_hook'
|
12
13
|
begin
|
@@ -40,6 +41,7 @@ require_relative 'rspec/empty_line_after_subject'
|
|
40
41
|
require_relative 'rspec/example_length'
|
41
42
|
require_relative 'rspec/example_without_description'
|
42
43
|
require_relative 'rspec/example_wording'
|
44
|
+
require_relative 'rspec/excessive_docstring_spacing'
|
43
45
|
require_relative 'rspec/expect_actual'
|
44
46
|
require_relative 'rspec/expect_change'
|
45
47
|
require_relative 'rspec/expect_in_hook'
|
@@ -88,6 +90,7 @@ require_relative 'rspec/shared_context'
|
|
88
90
|
require_relative 'rspec/shared_examples'
|
89
91
|
require_relative 'rspec/single_argument_message_chain'
|
90
92
|
require_relative 'rspec/stubbed_mock'
|
93
|
+
require_relative 'rspec/subject_declaration'
|
91
94
|
require_relative 'rspec/subject_stub'
|
92
95
|
require_relative 'rspec/unspecified_exception'
|
93
96
|
require_relative 'rspec/variable_definition'
|
@@ -5,6 +5,7 @@ module RuboCop
|
|
5
5
|
# Shared behavior for aligning braces for single line lets
|
6
6
|
class AlignLetBrace
|
7
7
|
include RuboCop::RSpec::Language
|
8
|
+
include RuboCop::Cop::Util
|
8
9
|
|
9
10
|
def initialize(root, token)
|
10
11
|
@root = root
|
@@ -34,7 +35,7 @@ module RuboCop
|
|
34
35
|
def let_group_for(let)
|
35
36
|
adjacent_let_chunks.detect do |chunk|
|
36
37
|
chunk.any? do |member|
|
37
|
-
member == let && member
|
38
|
+
member == let && same_line?(member, let)
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|
@@ -7,7 +7,8 @@ module RuboCop
|
|
7
7
|
# Builds a YAML config file from two config hashes
|
8
8
|
class ConfigFormatter
|
9
9
|
EXTENSION_ROOT_DEPARTMENT = %r{^(RSpec/)}.freeze
|
10
|
-
|
10
|
+
SUBDEPARTMENTS = %(RSpec/Capybara RSpec/FactoryBot RSpec/Rails)
|
11
|
+
COP_DOC_BASE_URL = 'https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/'
|
11
12
|
|
12
13
|
def initialize(config, descriptions)
|
13
14
|
@config = config
|
@@ -24,9 +25,10 @@ module RuboCop
|
|
24
25
|
|
25
26
|
def unified_config
|
26
27
|
cops.each_with_object(config.dup) do |cop, unified|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
next if SUBDEPARTMENTS.include?(cop)
|
29
|
+
|
30
|
+
unified[cop].merge!(descriptions.fetch(cop))
|
31
|
+
unified[cop]['Reference'] = COP_DOC_BASE_URL + cop.sub('RSpec/', '')
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module RSpec
|
5
|
+
module FactoryBot
|
6
|
+
# Contains node matchers for common FactoryBot DSL.
|
7
|
+
module Language
|
8
|
+
extend RuboCop::NodePattern::Macros
|
9
|
+
|
10
|
+
# @!method factory_bot?(node)
|
11
|
+
def_node_matcher :factory_bot?, <<~PATTERN
|
12
|
+
(const {nil? cbase} {:FactoryGirl :FactoryBot})
|
13
|
+
PATTERN
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/rubocop-rspec.rb
CHANGED
@@ -12,11 +12,14 @@ require_relative 'rubocop/rspec/wording'
|
|
12
12
|
require_relative 'rubocop/rspec/language/node_pattern'
|
13
13
|
require_relative 'rubocop/rspec/language'
|
14
14
|
|
15
|
+
require_relative 'rubocop/rspec/factory_bot/language'
|
16
|
+
|
15
17
|
require_relative 'rubocop/cop/rspec/mixin/top_level_group'
|
16
18
|
require_relative 'rubocop/cop/rspec/mixin/variable'
|
17
19
|
require_relative 'rubocop/cop/rspec/mixin/final_end_location'
|
18
20
|
require_relative 'rubocop/cop/rspec/mixin/comments_help'
|
19
21
|
require_relative 'rubocop/cop/rspec/mixin/empty_line_separation'
|
22
|
+
require_relative 'rubocop/cop/rspec/mixin/inside_example_group'
|
20
23
|
|
21
24
|
require_relative 'rubocop/rspec/concept'
|
22
25
|
require_relative 'rubocop/rspec/example_group'
|
@@ -31,8 +34,8 @@ RuboCop::RSpec::Inject.defaults!
|
|
31
34
|
|
32
35
|
require_relative 'rubocop/cop/rspec_cops'
|
33
36
|
|
34
|
-
# We have to register our autocorrect
|
35
|
-
# so we do not hit infinite loops
|
37
|
+
# We have to register our autocorrect incompatibilities in RuboCop's cops
|
38
|
+
# as well so we do not hit infinite loops
|
36
39
|
|
37
40
|
module RuboCop
|
38
41
|
module Cop
|
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.
|
4
|
+
version: 2.8.0
|
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:
|
13
|
+
date: 2022-01-24 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.
|
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.
|
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
|
@@ -97,19 +83,19 @@ dependencies:
|
|
97
83
|
- !ruby/object:Gem::Version
|
98
84
|
version: '1.7'
|
99
85
|
- !ruby/object:Gem::Dependency
|
100
|
-
name:
|
86
|
+
name: rubocop-rake
|
101
87
|
requirement: !ruby/object:Gem::Requirement
|
102
88
|
requirements:
|
103
|
-
- - "
|
89
|
+
- - "~>"
|
104
90
|
- !ruby/object:Gem::Version
|
105
|
-
version: '0.
|
91
|
+
version: '0.6'
|
106
92
|
type: :development
|
107
93
|
prerelease: false
|
108
94
|
version_requirements: !ruby/object:Gem::Requirement
|
109
95
|
requirements:
|
110
|
-
- - "
|
96
|
+
- - "~>"
|
111
97
|
- !ruby/object:Gem::Version
|
112
|
-
version: '0.
|
98
|
+
version: '0.6'
|
113
99
|
- !ruby/object:Gem::Dependency
|
114
100
|
name: yard
|
115
101
|
requirement: !ruby/object:Gem::Requirement
|
@@ -172,6 +158,7 @@ files:
|
|
172
158
|
- lib/rubocop/cop/rspec/example_length.rb
|
173
159
|
- lib/rubocop/cop/rspec/example_without_description.rb
|
174
160
|
- lib/rubocop/cop/rspec/example_wording.rb
|
161
|
+
- lib/rubocop/cop/rspec/excessive_docstring_spacing.rb
|
175
162
|
- lib/rubocop/cop/rspec/expect_actual.rb
|
176
163
|
- lib/rubocop/cop/rspec/expect_change.rb
|
177
164
|
- lib/rubocop/cop/rspec/expect_in_hook.rb
|
@@ -179,6 +166,7 @@ files:
|
|
179
166
|
- lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb
|
180
167
|
- lib/rubocop/cop/rspec/factory_bot/create_list.rb
|
181
168
|
- lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb
|
169
|
+
- lib/rubocop/cop/rspec/factory_bot/syntax_methods.rb
|
182
170
|
- lib/rubocop/cop/rspec/file_path.rb
|
183
171
|
- lib/rubocop/cop/rspec/focus.rb
|
184
172
|
- lib/rubocop/cop/rspec/hook_argument.rb
|
@@ -202,6 +190,7 @@ files:
|
|
202
190
|
- lib/rubocop/cop/rspec/mixin/comments_help.rb
|
203
191
|
- lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
|
204
192
|
- lib/rubocop/cop/rspec/mixin/final_end_location.rb
|
193
|
+
- lib/rubocop/cop/rspec/mixin/inside_example_group.rb
|
205
194
|
- lib/rubocop/cop/rspec/mixin/top_level_group.rb
|
206
195
|
- lib/rubocop/cop/rspec/mixin/variable.rb
|
207
196
|
- lib/rubocop/cop/rspec/multiple_describes.rb
|
@@ -230,6 +219,7 @@ files:
|
|
230
219
|
- lib/rubocop/cop/rspec/shared_examples.rb
|
231
220
|
- lib/rubocop/cop/rspec/single_argument_message_chain.rb
|
232
221
|
- lib/rubocop/cop/rspec/stubbed_mock.rb
|
222
|
+
- lib/rubocop/cop/rspec/subject_declaration.rb
|
233
223
|
- lib/rubocop/cop/rspec/subject_stub.rb
|
234
224
|
- lib/rubocop/cop/rspec/unspecified_exception.rb
|
235
225
|
- lib/rubocop/cop/rspec/variable_definition.rb
|
@@ -246,6 +236,7 @@ files:
|
|
246
236
|
- lib/rubocop/rspec/example.rb
|
247
237
|
- lib/rubocop/rspec/example_group.rb
|
248
238
|
- lib/rubocop/rspec/factory_bot.rb
|
239
|
+
- lib/rubocop/rspec/factory_bot/language.rb
|
249
240
|
- lib/rubocop/rspec/hook.rb
|
250
241
|
- lib/rubocop/rspec/inject.rb
|
251
242
|
- lib/rubocop/rspec/language.rb
|
@@ -259,6 +250,7 @@ licenses:
|
|
259
250
|
metadata:
|
260
251
|
changelog_uri: https://github.com/rubocop/rubocop-rspec/blob/master/CHANGELOG.md
|
261
252
|
documentation_uri: https://docs.rubocop.org/rubocop-rspec/
|
253
|
+
rubygems_mfa_required: 'true'
|
262
254
|
post_install_message:
|
263
255
|
rdoc_options: []
|
264
256
|
require_paths:
|
@@ -274,7 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
274
266
|
- !ruby/object:Gem::Version
|
275
267
|
version: '0'
|
276
268
|
requirements: []
|
277
|
-
rubygems_version: 3.
|
269
|
+
rubygems_version: 3.3.1
|
278
270
|
signing_key:
|
279
271
|
specification_version: 4
|
280
272
|
summary: Code style checking for RSpec files
|