Skip to content

Commit 0c091c0

Browse files
authored
Merge pull request #917 from rolfschmidt/followup-869
Fix `RSpec/FilePath` detection across sibling directories.
2 parents b15eefb + 23ad402 commit 0c091c0

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Expand `Capybara/VisibilityMatcher` to support more than just `have_selector`. ([@twalpole][])
88
* Add new `SpecSuffixOnly` option to `RSpec/FilePath` cop. ([@zdennis][])
99
* Allow `RSpec/RepeatedExampleGroupBody` to differ only by described_class. ([@robotdana][])
10+
* Fix `RSpec/FilePath` detection across sibling directories. ([@rolfschmidt][])
1011

1112
## 1.39.0 (2020-05-01)
1213

@@ -512,3 +513,4 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
512513
[@twalpole]: https://github.com/twalpole
513514
[@zdennis]: https://github.com/zdennis
514515
[@robotdana]: https://github.com/robotdana
516+
[@rolfschmidt]: https://github.com/rolfschmidt

lib/rubocop/cop/rspec/file_path.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def ignore_methods?
126126
def filename_ends_with?(glob)
127127
filename =
128128
RuboCop::PathUtil.relative_path(processed_source.buffer.name)
129+
.gsub('../', '')
129130
File.fnmatch?("*#{glob}", filename)
130131
end
131132

spec/rubocop/cop/rspec/file_path_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,24 @@
179179
RUBY
180180
end
181181

182+
it 'uses relative path for sibling directory project' do
183+
allow(RuboCop::PathUtil)
184+
.to receive(:relative_path)
185+
.and_return('../ext-project/spec/models/bar_spec.rb')
186+
expect_no_offenses(<<-RUBY, '/home/ext-project/spec/models/bar_spec.rb')
187+
describe Bar do; end
188+
RUBY
189+
end
190+
191+
it 'uses relative path for different path project' do
192+
allow(RuboCop::PathUtil)
193+
.to receive(:relative_path)
194+
.and_return('../../opt/ext-project/spec/models/bar_spec.rb')
195+
expect_no_offenses(<<-RUBY, '/opt/ext-project/spec/models/bar_spec.rb')
196+
describe Bar do; end
197+
RUBY
198+
end
199+
182200
context 'when configured with CustomTransform' do
183201
let(:cop_config) { { 'CustomTransform' => { 'FooFoo' => 'foofoo' } } }
184202

0 commit comments

Comments
 (0)