Skip to content

Commit

Permalink
Use relative path to match with glob
Browse files Browse the repository at this point in the history
  • Loading branch information
eitoball committed Feb 18, 2020
1 parent 94d8084 commit 811ae08
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Master (Unreleased)

* Fix `RSpec/FilePath` detection when absolute path includes test subject. ([@eitoball][])

## 1.38.1 (2020-02-15)

* Fix `RSpec/RepeatedDescription` to detect descriptions with interpolation and methods. ([@lazycoder9][])
Expand Down Expand Up @@ -489,3 +491,4 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
[@dduugg]: https://github.com/dduugg
[@lazycoder9]: https://github.com/lazycoder9
[@elebow]: https://github.com/elebow
[@eitoball]: https://github.com/eitoball
4 changes: 3 additions & 1 deletion lib/rubocop/cop/rspec/file_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ def ignore_methods?
end

def filename_ends_with?(glob)
File.fnmatch?("*#{glob}", processed_source.buffer.name)
filename =
RuboCop::PathUtil.relative_path(processed_source.buffer.name)
File.fnmatch?("*#{glob}", filename)
end

def relevant_rubocop_rspec_file?(_file)
Expand Down
9 changes: 9 additions & 0 deletions spec/rubocop/cop/rspec/file_path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@
RUBY
end

it 'uses relative path' do
allow(RuboCop::PathUtil)
.to receive(:relative_path).and_return('spec/models/bar_spec.rb')
expect_offense(<<-RUBY, '/home/foo/spec/models/bar_spec.rb')
describe Foo do; end
^^^^^^^^^^^^ Spec path should end with `foo*_spec.rb`.
RUBY
end

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

Expand Down

0 comments on commit 811ae08

Please sign in to comment.