Skip to content

Commit

Permalink
Merge pull request #869 from eitoball/use-relative-path-for-file_path…
Browse files Browse the repository at this point in the history
…-cop

Fix `FilePath` detection when absolute path includes test subject
  • Loading branch information
pirj authored Mar 25, 2020
2 parents 7970b19 + 811ae08 commit 84cca39
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 84cca39

Please sign in to comment.