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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ddf35b53864596c6fb017de51fcb89ba77720471a3eaa2dd02f250da1b434ffe
4
- data.tar.gz: a1aefe9d16cccac1d0d3d3bb19704e46cc91041c9f9c83f26cabbf419d75e162
3
+ metadata.gz: eb3dfbd46088f3d66b1af6e41c171aac15d8b28e5aae7f5c1eb43f770b47f423
4
+ data.tar.gz: 59ff08781d18888d37c3776209d3f90f0d7eee582a9cc03521048044c2ccf007
5
5
  SHA512:
6
- metadata.gz: 677edcd80bb8883e1c786f7a3d8665eac1082341652b050b2188f8cd242b5c632181f569081e7c656765a2abb8ce453c074aa1d1b7dd7304b830928da157bcc9
7
- data.tar.gz: 8b0a8211d5593d0bd20e984ff0daad1473c8b4ab75d7068aad3018dbc1b9036aa731d0c7aff7f12f9df8dbde91f554b4aabc002940000597ba2c8c4ee391ca5b
6
+ metadata.gz: 1446d96d3c63a526712f611a283bdf4758e39b7be63ae3c49e8aa66f916b55e4e495a5fae7bdd3ec5974189a1f6a5b4db211da58c031c2f5984703dff5f12cc3
7
+ data.tar.gz: c3ebd0c0cbc31647165384f04433fd62644d16aebf83ce1036770705900288cc0fda9c64ff6902f2ac36e23700862f420ef38d8693f641a86ee0dbed44733e34
@@ -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
@@ -328,6 +328,7 @@ RSpec/Focus:
328
328
  Description: Checks if examples are focused.
329
329
  Enabled: true
330
330
  VersionAdded: '1.5'
331
+ VersionChanged: '2.1'
331
332
  StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Focus
332
333
 
333
334
  RSpec/HookArgument:
@@ -82,30 +82,39 @@ module RuboCop
82
82
  private
83
83
 
84
84
  def ensure_correct_file_path(send_node, described_class, arguments)
85
- glob = glob_for(described_class, arguments.first)
86
- return if filename_ends_with?(glob)
87
-
88
- add_offense(send_node, message: format(MSG, suffix: glob))
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 glob_for(described_class, method_name)
96
- return glob_for_spec_suffix_only? if spec_suffix_only?
100
+ def pattern_for(described_class, method_name)
101
+ return pattern_for_spec_suffix_only? if spec_suffix_only?
97
102
 
98
- "#{expected_path(described_class)}#{name_glob(method_name)}*_spec.rb"
103
+ [
104
+ expected_path(described_class),
105
+ name_pattern(method_name),
106
+ '[^/]*_spec\.rb'
107
+ ].join
99
108
  end
100
109
 
101
- def glob_for_spec_suffix_only?
102
- '*_spec.rb'
110
+ def pattern_for_spec_suffix_only?
111
+ '.*_spec\.rb'
103
112
  end
104
113
 
105
- def name_glob(method_name)
114
+ def name_pattern(method_name)
106
115
  return unless method_name&.str_type?
107
116
 
108
- "*#{method_name.str_content.gsub(/\W/, '')}" unless ignore_methods?
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?(glob)
135
- filename =
136
- RuboCop::PathUtil.relative_path(processed_source.buffer.name)
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
@@ -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.0.1'
7
+ STRING = '2.1.0'
8
8
  end
9
9
  end
10
10
  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.1
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-02 00:00:00.000000000 Z
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.0.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