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

(PA-5641) Update rspec tests with modern Ruby #317

Merged
merged 6 commits into from
Jul 6, 2023

Conversation

mhashizume
Copy link
Contributor

This commit updates the versions of Ruby and Puppet that rspec tests run on to include Ruby 3.2 and Puppet 8.

@mhashizume mhashizume force-pushed the PA-5641/main/ruby-32 branch 2 times, most recently from 8492af8 to 71531ff Compare July 5, 2023 18:20
This commit updates the rspec GitHub Actions workflow to drop Puppet 6
and Ruby 2.5 and add Puppet 8 and its corresponding Rubies (MRI 3.2 and
JRuby 9.4.2.0).

Because of Ruby incompatibilities, this commit also updates tests to
run against specific pairings of Puppet and Ruby, instead of testing
the entire matrix against everything else.
This commit updates dead links in the README.
Prior to this commit, the `processing` method's final argument,
`message`, used a colon, which is the syntax for a keyword argument.
This does not seem to be the intended behavior given how the method is
called in tests, and may be an artifact from earlier versions of Ruby.

This commit updates the `processing` method's final argument from a
keyword argument to an optional positional argument by changing the
colon to an equals sign.
Prior to this commit, the `try_mungify` method used the `=~` method to
match numeric values to munge.

The `=~` method was removed for `Object` in Ruby 3.2[1]. This removal
causes failure in `try_mungify` as the class of the value parameter is
ambiguous and Ruby would attempt to call `=~` on every value.

However, `String` still has the `=~` method in Ruby 3.2 and since
`Object#=~` always returned nil before its removal, `try_mungify` likely
only ever matched on `String` objects to begin with.

This commit updates the logic in `try_mungify` to check whether the
value is a string, then checks for matches against numeric regex.

[1] https://bugs.ruby-lang.org/issues/15231
@mhashizume mhashizume force-pushed the PA-5641/main/ruby-32 branch 4 times, most recently from daa0d11 to 26d6c08 Compare July 6, 2023 20:51
Ruby >= 3.0 is more strict about interpreting keyword arguments than
previous Rubies. This commit updates rspec tests to receive an options
hashes instead of keyword arguments to enable these tests to run on Ruby
>= 3.0.

Additionally, this commit disables the Style/BracesAroundHashParameters
cop in Rubocop, as it is a style choice that conflicts with the
functionality of these options hashes. This cop may also be generating
false positives because the version of Rubocop that we're running is
over five years old and was released before the separation of positional
and keyword arguments that appeared in more recent versions of Ruby[1].

[1] https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/
When running rspec on Ruby 3.2, it interprets the `match` method
literally when used within a method call with other arguments, breaking
the test.

This commit updates that expectation to use `start_with` instead and opt
to match the string instead of regex.
@mhashizume mhashizume marked this pull request as ready for review July 6, 2023 21:29
@mhashizume mhashizume requested a review from a team as a code owner July 6, 2023 21:29
@joshcooper joshcooper merged commit fb0497d into puppetlabs:main Jul 6, 2023
6 checks passed
@mhashizume mhashizume deleted the PA-5641/main/ruby-32 branch July 7, 2023 00:01
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.

Munging fails on Integer data type when passed value is an integer or a float
2 participants