Skip to content

Commit 02d6e30

Browse files
authored
Merge pull request #1286 from tejasbubane/fix-1105
Fix incorrect path suggested by `RSpec/FilePath` cop when second argument contains spaces
2 parents 55d052a + 1da71cb commit 02d6e30

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## Master (Unreleased)
4+
* Fix incorrect path suggested by `RSpec/FilePath` cop when second argument contains spaces. ([@tejasbubane][])
45

56
## 2.11.1 (2022-05-18)
67

lib/rubocop/cop/rspec/file_path.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ def pattern_for_spec_suffix_only?
117117

118118
def name_pattern(method_name)
119119
return unless method_name&.str_type?
120+
return if ignore_methods?
120121

121-
".*#{method_name.str_content.gsub(/\W/, '')}" unless ignore_methods?
122+
".*#{method_name.str_content.gsub(/\s/, '_').gsub(/\W/, '')}"
122123
end
123124

124125
def expected_path(constant)

spec/rubocop/cop/rspec/file_path_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@
5757
RUBY
5858
end
5959

60+
it 'registers an offense when second argument contains spaces' do
61+
expect_offense(<<-RUBY, 'wrong_class_spec.rb')
62+
describe MyClass, "via `local_failures`" do; end
63+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Spec path should end with `my_class*via_local_failures*_spec.rb`.
64+
RUBY
65+
end
66+
6067
it 'registers an offense for a file missing _spec' do
6168
expect_offense(<<-RUBY, 'spec/models/user.rb')
6269
describe User do; end

0 commit comments

Comments
 (0)