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
(PUP-4698) Change fqdn_rand's return type to Integer #4020
(PUP-4698) Change fqdn_rand's return type to Integer #4020
Conversation
Before this, fqdn_rand always returned a String. That is not the best choice for a numeric value now that the evaluator is aware of different data types as comparissons will typically be wrong (since '2' > '19' when compared leicographically). This fix adds a utility method that returns an integer version while the old utility method producing a string is retained for those that use Puppet as an API. The function now uses the integer version of this utility method. A test is added that asserts that an Integer is produced. At some point it would be beneficial to reimplement the function using the 4.x function API as it will simply raise a generic error if given input of the wrong type. It will also magically change a floating point input value to integer.
App Veyor failing with known issues regarding rdoc |
CLA signed by all contributors. |
it "returns an integer" do | ||
expect(fqdn_rand(3)).to satisfy {|n| n.is_a?(Integer) } | ||
end | ||
|
||
it "provides a random number strictly less than the given max" do | ||
expect(fqdn_rand(3)).to satisfy {|n| n.to_i < 3 } |
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.
can the to_i
go away now?
Other than that one nit in the spec, I'm 👍 |
And appveyor failures are the usual rdoc ones. Known bogo-failure. |
|
||
|
||
it "returns an integer" do | ||
expect(fqdn_rand(3)).to satisfy {|n| n.is_a?(Integer) } |
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.
Simpler as expect(fqdn_rand(3)).to be_a(Integer)
ok - two nits - will update |
* no need to convert to integer in test asserts since fqdn now returns and integer * simplified assert using be_an instead of satisfies
…n-numric (PUP-4698) Change fqdn_rand's return type to Integer
Before this, fqdn_rand always returned a String. That is not the best
choice for a numeric value now that the evaluator is aware of different
data types as comparissons will typically be wrong (since '2' > '19'
when compared leicographically).
This fix adds a utility method that returns an integer version while the
old utility method producing a string is retained for those that use
Puppet as an API. The function now uses the integer version of this
utility method.
A test is added that asserts that an Integer is produced.
At some point it would be beneficial to reimplement the function using
the 4.x function API as it will simply raise a generic error if given
input of the wrong type. It will also magically change a floating point
input value to integer.