Skip to content

Commit

Permalink
Fix RSpec/FilePath detection across sibling directories.
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfschmidt committed Jun 2, 2020
1 parent a8d756a commit 23ad402
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 23ad402

Please sign in to comment.