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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
pull_request:
branches: [ main ]

permissions:
contents: read

jobs:
test:

Expand All @@ -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
Expand Down
17 changes: 7 additions & 10 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down