-
-
Notifications
You must be signed in to change notification settings - Fork 389
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 specs for Random::Formatter#alphanumeric #1222
base: master
Are you sure you want to change the base?
Conversation
There are failures on Ruby 3.0. Could you please take a look? |
to_s.should_receive(:to_s).and_return("[mock to_s]") | ||
# Using 1 value in chars results in an infinite loop | ||
Random.alphanumeric(1, chars: [to_s, to_s]).should == "[mock to_s]" | ||
end |
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.
It seems chars
could contain more than 1 character and all of them will be used, not the first one. But documentation states that The argument chars specifies the character list ...
. As for me it's worth adding a dedicated test case for it.
99662b8
to
05ac137
Compare
require_relative '../../spec_helper' | ||
|
||
ruby_version_is "3.1" do | ||
require 'random/formatter' |
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.
Looks like Random::Formatter
was available in Ruby 3.0 but was part of securerandom
.
Random::Formatter is moved to random/formatter.rb, so that you can use Random#hex, Random#base64, and so on without SecureRandom. [Feature #18190]
https://github.com/ruby/ruby/blob/v3_1_0/NEWS.md
https://bugs.ruby-lang.org/issues/18190
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.
And it seems Random::Formatter
's methods are available on SecureRandom
. So ideally we would want to have a shared example to test #alphanumeric
for both Random::Formatter
and SequreRandom
.
SecureRandom.method(:alphanumeric)
# => #<Method: #<Class:SecureRandom>(Random::Formatter)#alphanumeric(n=..., chars: ...)
JFYI there are specs of Random::Formatter
methods in https://github.com/ruby/spec/tree/master/library/securerandom that would probably also might be shared.
Another one for Ruby 3.3 (#1216), but this adds some specs for earlier Ruby versions too.
There are more methods defined on RandomFormatter, we should probably add specs for the remaining methods too.