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

Add test for Float#to_i raising FloatDomainError when NaN #958

Merged
merged 2 commits into from
Oct 13, 2022

Conversation

stevegeek
Copy link
Contributor

Hey all!

While working on https://github.com/natalie-lang/natalie I noticed that the specs for to_i on Floats did not check that it raises a FloatDomainError when NaN

So adding a little extra check for that. Let me know if the assertion has been added to the correct example

Context: FloatDomainError

@@ -1,5 +1,6 @@
describe :float_to_i, shared: true do
it "returns self truncated to an Integer" do
-> { (0.0 / 0.0).send(@method) }.should raise_error(FloatDomainError)
Copy link
Member

@eregon eregon Oct 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this to a separate it example?
In general we shouldn't mix normal and exceptional cases in a single it, and also this behavior does not match the example description.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, will do!

Copy link
Member

@eregon eregon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, looks good!

@eregon eregon merged commit 5415af3 into ruby:master Oct 13, 2022
@stevegeek
Copy link
Contributor Author

Thanks @eregon !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants