Skip to content

RSpec: Use conditional hooks for money precision #1138

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tagliala
Copy link
Contributor

@tagliala tagliala commented Jul 12, 2025


Move the Money.default_infinite_precision test setup from a shared context into global, conditional RSpec hooks.

The previous shared_context approach, which relied on implicit metadata inclusion, is deprecated and was failing with the modern shared_context_metadata_behavior = :apply_to_host_groups setting.

An explicit include_context is unsuitable because this behavior is sometimes required for individual examples (it blocks), where contexts cannot be included.

This commit defines global before and after hooks in the RSpec configuration that are filtered by the
:default_infinite_precision_true metadata tag. This provides a declarative and efficient way to apply the necessary setup and teardown to any example group or individual example without repetitive code, while aligning with modern RSpec practices.

Close #1136

@tagliala tagliala force-pushed the chore/1136-prepare-for-rspec-4 branch from 4e32ce0 to 58b85a1 Compare July 12, 2025 15:28
@tagliala tagliala changed the title Use conditional hooks for money precision RSpec: Use conditional hooks for money precision (non-breaking, non-production) Jul 12, 2025
@tagliala tagliala force-pushed the chore/1136-prepare-for-rspec-4 branch from 58b85a1 to e5dd1b1 Compare July 13, 2025 10:03
@tagliala tagliala marked this pull request as draft July 13, 2025 10:05
@tagliala
Copy link
Contributor Author

tagliala commented Jul 13, 2025

Failures:

  1) Money::Currency#initialize is thread safe
     Failure/Error: expect(ids.uniq.length).to eq(1)

       expected: 1
            got: 2

       (compared using ==)
     # ./spec/currency_spec.rb:249:in 'block in <main>'

rspec ./spec/currency_spec.rb:246 # Money::Currency#initialize is thread safe

🤔


This looks to be a random failure. I can't replicate this locally

Finished in 9.41 seconds (files took 5.86 seconds to load)
515 examples, 0 failures

Randomized with seed 9926

@tagliala tagliala force-pushed the chore/1136-prepare-for-rspec-4 branch 2 times, most recently from 76d2ac2 to dc065ef Compare July 13, 2025 10:32
@tagliala tagliala marked this pull request as ready for review July 13, 2025 10:42
@tagliala tagliala changed the title RSpec: Use conditional hooks for money precision (non-breaking, non-production) RSpec: Use conditional hooks for money precision (non-breaking, non-production, may introduce a random failure with JRuby 10 😞) Jul 13, 2025
@tagliala tagliala force-pushed the chore/1136-prepare-for-rspec-4 branch 2 times, most recently from 9685ee5 to 5b448a0 Compare July 13, 2025 10:47
@tagliala tagliala changed the title RSpec: Use conditional hooks for money precision (non-breaking, non-production, may introduce a random failure with JRuby 10 😞) RSpec: Use conditional hooks for money precision Jul 13, 2025
tagliala added 2 commits July 15, 2025 15:14
Workflows run with extended set of permissions by default.
By specifying any permission explicitly, all others are set to none.

Ref: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions

JRuby 10.0 Requires Java 21 but Java 17 was used. This eliminates the following
error:

```
Error: LinkageError occurred while loading main class org.jruby.Main
java.lang.UnsupportedClassVersionError: org/jruby/Main has been compiled by a more recent version of the Java Runtime (class file version 65.0), this version of the Java Runtime only recognizes class file versions up to 61.0
JRuby failed to start, try Java 21 envs
```
Move the `Money.default_infinite_precision` test setup from a shared
context into global, conditional RSpec hooks.

The previous `shared_context` approach, which relied on implicit
metadata inclusion, is deprecated and was failing with the modern
`shared_context_metadata_behavior = :apply_to_host_groups` setting.

An explicit `include_context` is unsuitable because this behavior is
sometimes required for individual examples (`it` blocks), where
contexts cannot be included.

This commit defines global `before` and `after` hooks in the RSpec
configuration that are filtered by the
`:default_infinite_precision_true` metadata tag. This provides a
declarative and efficient way to apply the necessary setup and teardown
to any example group or individual example without repetitive code,
while aligning with modern RSpec practices.

Close RubyMoney#1136
@tagliala tagliala force-pushed the chore/1136-prepare-for-rspec-4 branch from 5b448a0 to 83d2622 Compare July 15, 2025 13:14
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.

Preparing for RSpec4: Running specs fail with shared_context_metadata_behavior = :apply_to_host_groups
2 participants