Skip to content

Commit

Permalink
Merge pull request #917 from rolfschmidt/followup-869
Browse files Browse the repository at this point in the history
Fix `RSpec/FilePath` detection across sibling directories.
  • Loading branch information
bquorning committed Jun 2, 2020
2 parents b15eefb + 23ad402 commit 0c091c0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Expand `Capybara/VisibilityMatcher` to support more than just `have_selector`. ([@twalpole][])
* Add new `SpecSuffixOnly` option to `RSpec/FilePath` cop. ([@zdennis][])
* Allow `RSpec/RepeatedExampleGroupBody` to differ only by described_class. ([@robotdana][])
* Fix `RSpec/FilePath` detection across sibling directories. ([@rolfschmidt][])

## 1.39.0 (2020-05-01)

Expand Down Expand Up @@ -512,3 +513,4 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
[@twalpole]: https://github.com/twalpole
[@zdennis]: https://github.com/zdennis
[@robotdana]: https://github.com/robotdana
[@rolfschmidt]: https://github.com/rolfschmidt
1 change: 1 addition & 0 deletions lib/rubocop/cop/rspec/file_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def ignore_methods?
def filename_ends_with?(glob)
filename =
RuboCop::PathUtil.relative_path(processed_source.buffer.name)
.gsub('../', '')
File.fnmatch?("*#{glob}", filename)
end

Expand Down
18 changes: 18 additions & 0 deletions spec/rubocop/cop/rspec/file_path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,24 @@
RUBY
end

it 'uses relative path for sibling directory project' do
allow(RuboCop::PathUtil)
.to receive(:relative_path)
.and_return('../ext-project/spec/models/bar_spec.rb')
expect_no_offenses(<<-RUBY, '/home/ext-project/spec/models/bar_spec.rb')
describe Bar do; end
RUBY
end

it 'uses relative path for different path project' do
allow(RuboCop::PathUtil)
.to receive(:relative_path)
.and_return('../../opt/ext-project/spec/models/bar_spec.rb')
expect_no_offenses(<<-RUBY, '/opt/ext-project/spec/models/bar_spec.rb')
describe Bar do; end
RUBY
end

context 'when configured with CustomTransform' do
let(:cop_config) { { 'CustomTransform' => { 'FooFoo' => 'foofoo' } } }

Expand Down

0 comments on commit 0c091c0

Please sign in to comment.