Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

robaiken
Copy link
Contributor

@robaiken robaiken requested a review from a team as a code owner May 15, 2024 16:16
@robaiken robaiken self-assigned this May 15, 2024
@@ -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
Copy link
Member

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?

Copy link
Member

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 😬

Copy link
Contributor Author

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.

Copy link
Member

@jurre jurre May 16, 2024

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 🤔

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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 👇

Suggested change
expect(File.read(".npmrc")).not_to be_empty
expect(File.empty?(".npmrc")).to be_truthy

Copy link
Contributor Author

@robaiken robaiken May 17, 2024

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.

Copy link
Member

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!

@robaiken robaiken linked an issue May 23, 2024 that may be closed by this pull request
@GarryHurleyJr GarryHurleyJr force-pushed the robaiken/enable-RSpec-VoidExpect branch from 607f790 to ff65e81 Compare June 4, 2024 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable New RuboCop Cops
3 participants