rubocop-rspec 2.0.1 → 2.1.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 +7 -0
- data/config/default.yml +1 -0
- data/lib/rubocop/cop/rspec/file_path.rb +23 -16
- data/lib/rubocop/cop/rspec/focus.rb +30 -1
- data/lib/rubocop/rspec/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb3dfbd46088f3d66b1af6e41c171aac15d8b28e5aae7f5c1eb43f770b47f423
|
4
|
+
data.tar.gz: 59ff08781d18888d37c3776209d3f90f0d7eee582a9cc03521048044c2ccf007
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1446d96d3c63a526712f611a283bdf4758e39b7be63ae3c49e8aa66f916b55e4e495a5fae7bdd3ec5974189a1f6a5b4db211da58c031c2f5984703dff5f12cc3
|
7
|
+
data.tar.gz: c3ebd0c0cbc31647165384f04433fd62644d16aebf83ce1036770705900288cc0fda9c64ff6902f2ac36e23700862f420ef38d8693f641a86ee0dbed44733e34
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
## Master (Unreleased)
|
4
4
|
|
5
|
+
## 2.1.0 (2020-12-17)
|
6
|
+
|
7
|
+
* Fix `RSpec/FilePath` false positive for relative file path runs with long namespaces. ([@ahukkanen][])
|
8
|
+
* Update `RSpec/Focus` to have auto-correction. ([@dvandersluis][])
|
9
|
+
|
5
10
|
## 2.0.1 (2020-12-02)
|
6
11
|
|
7
12
|
* Fixed infinite loop in `RSpec/ExpectActual` autocorrection when both expected and actual values are literals. ([@Darhazer][])
|
@@ -590,3 +595,5 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
|
|
590
595
|
[@Rafix02]: https://github.com/Rafix02
|
591
596
|
[@PhilCoggins]: https://github.com/PhilCoggins
|
592
597
|
[@sl4vr]: https://github.com/sl4vr
|
598
|
+
[@ahukkanen]: https://github.com/ahukkanen
|
599
|
+
[@dvandersluis]: https://github.com/dvandersluis
|
data/config/default.yml
CHANGED
@@ -82,30 +82,39 @@ module RuboCop
|
|
82
82
|
private
|
83
83
|
|
84
84
|
def ensure_correct_file_path(send_node, described_class, arguments)
|
85
|
-
|
86
|
-
return if filename_ends_with?(
|
87
|
-
|
88
|
-
|
85
|
+
pattern = pattern_for(described_class, arguments.first)
|
86
|
+
return if filename_ends_with?(pattern)
|
87
|
+
|
88
|
+
# For the suffix shown in the offense message, modify the regular
|
89
|
+
# expression pattern to resemble a glob pattern for clearer error
|
90
|
+
# messages.
|
91
|
+
offense_suffix = pattern.gsub('.*', '*').sub('[^/]', '')
|
92
|
+
.sub('\.', '.')
|
93
|
+
add_offense(send_node, message: format(MSG, suffix: offense_suffix))
|
89
94
|
end
|
90
95
|
|
91
96
|
def routing_spec?(args)
|
92
97
|
args.any?(&method(:routing_metadata?))
|
93
98
|
end
|
94
99
|
|
95
|
-
def
|
96
|
-
return
|
100
|
+
def pattern_for(described_class, method_name)
|
101
|
+
return pattern_for_spec_suffix_only? if spec_suffix_only?
|
97
102
|
|
98
|
-
|
103
|
+
[
|
104
|
+
expected_path(described_class),
|
105
|
+
name_pattern(method_name),
|
106
|
+
'[^/]*_spec\.rb'
|
107
|
+
].join
|
99
108
|
end
|
100
109
|
|
101
|
-
def
|
102
|
-
'
|
110
|
+
def pattern_for_spec_suffix_only?
|
111
|
+
'.*_spec\.rb'
|
103
112
|
end
|
104
113
|
|
105
|
-
def
|
114
|
+
def name_pattern(method_name)
|
106
115
|
return unless method_name&.str_type?
|
107
116
|
|
108
|
-
"
|
117
|
+
".*#{method_name.str_content.gsub(/\W/, '')}" unless ignore_methods?
|
109
118
|
end
|
110
119
|
|
111
120
|
def expected_path(constant)
|
@@ -131,11 +140,9 @@ module RuboCop
|
|
131
140
|
cop_config['IgnoreMethods']
|
132
141
|
end
|
133
142
|
|
134
|
-
def filename_ends_with?(
|
135
|
-
filename =
|
136
|
-
|
137
|
-
.gsub('../', '')
|
138
|
-
File.fnmatch?("*#{glob}", filename)
|
143
|
+
def filename_ends_with?(pattern)
|
144
|
+
filename = File.expand_path(processed_source.buffer.name)
|
145
|
+
filename.match?("#{pattern}$")
|
139
146
|
end
|
140
147
|
|
141
148
|
def relevant_rubocop_rspec_file?(_file)
|
@@ -20,6 +20,9 @@ module RuboCop
|
|
20
20
|
# describe MyClass do
|
21
21
|
# end
|
22
22
|
class Focus < Base
|
23
|
+
extend AutoCorrector
|
24
|
+
include RangeHelp
|
25
|
+
|
23
26
|
MSG = 'Focused spec found.'
|
24
27
|
|
25
28
|
def_node_matcher :focusable_selector?, <<-PATTERN
|
@@ -44,7 +47,13 @@ module RuboCop
|
|
44
47
|
|
45
48
|
def on_send(node)
|
46
49
|
focus_metadata(node) do |focus|
|
47
|
-
add_offense(focus)
|
50
|
+
add_offense(focus) do |corrector|
|
51
|
+
if focus.pair_type? || focus.str_type? || focus.sym_type?
|
52
|
+
corrector.remove(with_surrounding(focus))
|
53
|
+
elsif focus.send_type?
|
54
|
+
correct_send(corrector, focus)
|
55
|
+
end
|
56
|
+
end
|
48
57
|
end
|
49
58
|
end
|
50
59
|
|
@@ -55,6 +64,26 @@ module RuboCop
|
|
55
64
|
|
56
65
|
metadata(node, &block)
|
57
66
|
end
|
67
|
+
|
68
|
+
def with_surrounding(focus)
|
69
|
+
range_with_space = range_with_surrounding_space(
|
70
|
+
range: focus.loc.expression,
|
71
|
+
side: :left
|
72
|
+
)
|
73
|
+
|
74
|
+
range_with_surrounding_comma(range_with_space, :left)
|
75
|
+
end
|
76
|
+
|
77
|
+
def correct_send(corrector, focus)
|
78
|
+
range = focus.loc.selector
|
79
|
+
unfocused = focus.method_name.to_s.sub(/^f/, '')
|
80
|
+
unless Examples.regular(unfocused) || ExampleGroups.regular(unfocused)
|
81
|
+
return
|
82
|
+
end
|
83
|
+
|
84
|
+
corrector.replace(range,
|
85
|
+
range.source.sub(focus.method_name.to_s, unfocused))
|
86
|
+
end
|
58
87
|
end
|
59
88
|
end
|
60
89
|
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.0
|
4
|
+
version: 2.1.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: 2020-12-
|
13
|
+
date: 2020-12-17 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -271,7 +271,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
271
271
|
- !ruby/object:Gem::Version
|
272
272
|
version: '0'
|
273
273
|
requirements: []
|
274
|
-
rubygems_version: 3.
|
274
|
+
rubygems_version: 3.2.2
|
275
275
|
signing_key:
|
276
276
|
specification_version: 4
|
277
277
|
summary: Code style checking for RSpec files
|