-
-
Notifications
You must be signed in to change notification settings - Fork 500
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
Use a more expressive method of rewriting values #975
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,9 +44,8 @@ | |
end | ||
|
||
it 'accepts a valid hash for value' do | ||
value = { 'message-ttl' => '1800000' } | ||
parameter[:value] = value | ||
expect(parameter[:value]).to eq(value) | ||
parameter[:value] = { 'message-ttl' => '1800000' } | ||
expect(parameter[:value]).to eq({ 'message-ttl' => 1_800_000 }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will get turned back into a string if needed, I assume? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I know, the code always did this. The tests just weren't explicit about it and relied on the side effect of |
||
end | ||
|
||
it 'does not accept an empty string for definition' do | ||
|
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.
This would fail on Ruby 3.2 where
[] =~ //
is no longer defined, breaking Puppet 8. That's why I switched over to the string check. I also usematch?
because it's faster if you don't need the resulting match.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.
but now
Failure/Error: expect(parameter[:value]).to eq(value)
expected: {"message-ttl"=>"1800000"}
got: {"message-ttl"=>1800000}
as said I've add next if array on the value iteration and ti "fix" the test on puppet 8
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.
That's a side effect of the change. Previously the passed in value was modified in place and the tests (incorrectly) relied on that. I've modified that.
I think that's wrong. Your code can still fail on other non-string and non-array types because https://bugs.ruby-lang.org/issues/15231 changed the behavior.
That's why I explicitly chose
is_a?(String)
.You could write
/regex/.match?(v)
but you'd get a TypeError if you pass in a non-string: