Skip to content

Comments

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

Merged
eregon merged 2 commits intoruby:masterfrom
stevegeek:add_nan_to_i_raises_test
Oct 13, 2022
Merged

Add test for Float#to_i raising FloatDomainError when NaN#958
eregon merged 2 commits intoruby:masterfrom
stevegeek:add_nan_to_i_raises_test

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants