-
-
Notifications
You must be signed in to change notification settings - Fork 277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix FilePath
detection when absolute path includes test subject
#869
Fix FilePath
detection when absolute path includes test subject
#869
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Will you please add a spec for this change?
FilePath
detection when absolute path includes test subject
e7ec9b3
to
f91e85b
Compare
Added. But, it's quite dirty... |
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible to call rubocop
from a subdirectory, e.g. /home/foo/spec/models/
, in this case relative path will be ./bar_spec.rb
, this shouldn't cause any thouble, should it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it depends. If subject is like 'Foo::Bar', it wouldn't detect. I think that most people run from project root
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems this way it doesn't work if I run rubocop and provide a path to check, e.g.
rubocop --require rubocop-rspec ~/my_project/specs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eitoball Can you please check this edge case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I didn't notice. Will do over this weekend. Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A friendly reminder. This is ready to be merged apart from this edge case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi guys,
i think i had this edge case. I tried to create a pull request for it:
03dddb8
to
9030ad4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you!
@eitoball Can you please rebase? @bquorning @Darhazer @lazycoder9 What are your thoughts on this? |
9030ad4
to
2126827
Compare
@pirj Rebased. |
2126827
to
811ae08
Compare
Thanks a lot for your contribution! |
This PR should fix
FilePath
cop when test subject is accidentally included in absolute path of file that being examined. For example, if file contains following spec,and the absolute path name is like
/home/foo/src/spec/models/bar_spec.rb
.I think this case should be warned, but currently it is passed because glob pattern
foo*_spec.rb
matches.This PR changes to use relative path from project root so that it wouldn't match this case.
Before submitting the PR make sure the following are checked:
master
(if not - rebase it).bundle exec rake
) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).