From 5dd51d05921b244fb91a4cb9c970c01940c9bac7 Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Sun, 13 Jul 2025 12:26:22 +0200 Subject: [PATCH 1/2] Improve CI permissions and fix Java for JRuby 10 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 ``` --- .github/workflows/ruby.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 94104b22c7..66157e1f53 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -6,6 +6,9 @@ on: pull_request: branches: [ main ] +permissions: + contents: read + jobs: test: @@ -15,6 +18,12 @@ jobs: ruby-version: ['3.1', '3.2', '3.3', '3.4', 'jruby-9.4', 'jruby-10.0'] steps: + - name: Set up Java for JRuby 10.0 + if: matrix.ruby-version == 'jruby-10.0' + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '21' - uses: actions/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 From 83d262224927078e94dccd43fb5ab170f0ff8f80 Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Sat, 12 Jul 2025 11:30:56 +0200 Subject: [PATCH 2/2] Use conditional hooks for money precision 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 --- spec/spec_helper.rb | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7b4b497229..ae5532aaa5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -62,8 +62,7 @@ # compatibility in RSpec 3). It causes shared context metadata to be # inherited by the metadata hash of host groups and examples, rather than # triggering implicit auto-inclusion in groups with matching metadata. - # TODO: enable this option. Tracked in RubyMoney/money#1136 - # config.shared_context_metadata_behavior = :apply_to_host_groups + config.shared_context_metadata_behavior = :apply_to_host_groups # This allows you to limit a spec run to individual examples or groups # you care about by tagging them with `:focus` metadata. When nothing @@ -112,22 +111,20 @@ # test failures related to randomization by passing the same `--seed` value # as the one that triggered the failure. Kernel.srand config.seed -end - -def reset_i18n - I18n.backend = I18n::Backend::Simple.new -end -RSpec.shared_context "with infinite precision", :default_infinite_precision_true do - before do + config.before(:each, :default_infinite_precision_true) do Money.default_infinite_precision = true end - after do + config.after(:each, :default_infinite_precision_true) do Money.default_infinite_precision = false end end +def reset_i18n + I18n.backend = I18n::Backend::Simple.new +end + class Money module Warning def warn(message); end