-
Notifications
You must be signed in to change notification settings - Fork 919
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
Enabling RSpec/VoidExpect #9738
base: main
Are you sure you want to change the base?
Conversation
@@ -87,7 +87,7 @@ def project_dependency_file(file_name) | |||
expect(Dir.children(".")).to match_array( | |||
%w(package.json .npmrc .yarnrc) | |||
) | |||
expect(File.empty?(".npmrc")) | |||
expect(File.read(".npmrc")).not_to be_empty |
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.
This inverts the expectation doesn't 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.
Very confused why this doesn't break any of the tests 😬
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.
Yea, @jurre , it shouldn't work, but I don't want to delay this epic for a broken test. I can either skip the test or leave it as it is, but I will raise an issue.
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'm just surprised that it was passing before. Is there a subtle difference between File.empty?
and File.read.empty?
maybe? Perhaps when the file does not exist?
File.empty?
(alias of File.zero?
):
Returns true if the named file exists and has a zero size.
Whereas File.read
would raise if the file doesn't exist. Which, wouldn't really explain the test here passing. I also checked with something like a space, but behaves the same there, as expected 🤔
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 assume .npmrc
has a zero size. File.read
won't blow up if the file exists (which it does, as shown in the expectation a few lines up), but is empty.
dependabot@codespaces-a9309d:/app$ touch .npmrc
dependabot@codespaces-a9309d:/app$ irb
irb(main):001> File.read(".npmrc").empty?
=> true
File.read
returns a String
, and String#empty?
will have different implications.
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.
Is this expected behaviour? Should I update the test to reflect this? It seems like a bug and we should log it as an issue
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.
Is this expected behaviour?
There are enough references in this thread that I'm not 100% sure which behavior you're referring to 🙈
My hope is that the (perceived) intent of the test will remain. The expectation could be updated to maintain the current behavior with something like 👇
expect(File.read(".npmrc")).not_to be_empty | |
expect(File.empty?(".npmrc")).to be_truthy |
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.
@landongrindheim it looks like File.empty?(".npmrc")
returns false
.
There are enough references in this thread that I'm not 100% sure which behavior you're referring to 🙈
Lol, sorry, you are right. The behavior I am referring to is whether .npmrc should exist in this scenario. It seems like the original test was not set up correctly as it did not have an assertion, so it passes every time. If that's the case, then it's weird that RSpec doesn't log that the test has no assertions.
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.
@robaiken 👍 In that case, I think it makes sense to make the test honest and ensure that the assertions are inline with the intent of the tests. Good find!
607f790
to
ff65e81
Compare
https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecvoidexpect