From 919f88df87954bf461a2e0a1facb4a23bf7528d6 Mon Sep 17 00:00:00 2001 From: Sunny Ripert Date: Mon, 2 Feb 2026 18:52:12 +0100 Subject: [PATCH 1/7] Lint: Fix RSpec cops Fixes the following cops: - RSpec/MultipleDescribes - RSpecRails/InferredSpecType - RSpec/ExampleWording --- .rubocop_todo.yml | 21 +-------------------- spec/active_record/monetizable_spec.rb | 6 +++--- spec/configuration_spec.rb | 2 +- spec/helpers/action_view_extension_spec.rb | 2 -- spec/helpers/form_helper_spec.rb | 2 +- 5 files changed, 6 insertions(+), 27 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 680031b57..8893dceec 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config --no-offense-counts --no-auto-gen-timestamp` -# using RuboCop version 1.82.1. +# using RuboCop version 1.84.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -58,14 +58,6 @@ RSpec/DescribeClass: RSpec/ExampleLength: Max: 24 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: CustomTransform, IgnoredWords, DisallowedExamples. -# DisallowedExamples: works -RSpec/ExampleWording: - Exclude: - - 'spec/active_record/monetizable_spec.rb' - - 'spec/configuration_spec.rb' - RSpec/ExpectInHook: Exclude: - 'spec/helpers/action_view_extension_spec.rb' @@ -96,10 +88,6 @@ RSpec/LeadingSubject: RSpec/MessageSpies: EnforcedStyle: receive -RSpec/MultipleDescribes: - Exclude: - - 'spec/helpers/action_view_extension_spec.rb' - # Configuration parameters: AllowSubject. RSpec/MultipleMemoizedHelpers: Max: 11 @@ -157,13 +145,6 @@ RSpec/VerifiedDoubles: Exclude: - 'spec/active_record/monetizable_spec.rb' -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: Inferences. -RSpecRails/InferredSpecType: - Exclude: - - 'spec/helpers/action_view_extension_spec.rb' - - 'spec/helpers/form_helper_spec.rb' - Style/ClassVars: Exclude: - 'lib/money-rails/configuration.rb' diff --git a/spec/active_record/monetizable_spec.rb b/spec/active_record/monetizable_spec.rb index 0e457c06a..cac539e07 100644 --- a/spec/active_record/monetizable_spec.rb +++ b/spec/active_record/monetizable_spec.rb @@ -36,7 +36,7 @@ def price=(value) expect(p.side_effect).to be_truthy end - it "should be inherited by subclasses" do + it "is inherited by subclasses" do sub_class = Class.new(Product) assert_monetized_attributes( sub_class.monetized_attributes, @@ -44,7 +44,7 @@ def price=(value) ) end - it "should be inherited by subclasses with new monetized attribute" do + it "is inherited by subclasses with new monetized attribute" do inherited_class = Class.new(Product) do monetize :special_price_cents end @@ -258,7 +258,7 @@ def assert_monetized_attributes(monetized_attributes, expected_attributes) expect(product.save).to be_truthy end - it "shouldn't init empty key in errors" do + it "does not init empty key in errors" do product.price = Money.new(320, "USD") product.valid? expect(product.errors.key?(:price)).to be_falsey diff --git a/spec/configuration_spec.rb b/spec/configuration_spec.rb index 9dbfd59de..83b66986c 100644 --- a/spec/configuration_spec.rb +++ b/spec/configuration_spec.rb @@ -137,7 +137,7 @@ end context "when passed an invalid value" do - it "should raise an ArgumentError" do + it "raises an ArgumentError" do expect { MoneyRails.rounding_mode = "booyakasha" }.to raise_error(ArgumentError, "booyakasha is not a valid rounding mode") end end diff --git a/spec/helpers/action_view_extension_spec.rb b/spec/helpers/action_view_extension_spec.rb index 696d157c6..508b5b98e 100644 --- a/spec/helpers/action_view_extension_spec.rb +++ b/spec/helpers/action_view_extension_spec.rb @@ -8,9 +8,7 @@ expect(MoneyRails.autoload?(:ActionViewExtension)).to eq("money-rails/helpers/action_view_extension") end end -end -describe "MoneyRails::ActionViewExtension", type: :helper do describe "#currency_symbol" do subject { helper.currency_symbol } diff --git a/spec/helpers/form_helper_spec.rb b/spec/helpers/form_helper_spec.rb index 20e668bf0..63ef4468b 100644 --- a/spec/helpers/form_helper_spec.rb +++ b/spec/helpers/form_helper_spec.rb @@ -3,7 +3,7 @@ require "spec_helper" if defined? ActiveRecord - describe "Test helper in form blocks", type: :helper do + describe "Test helper in form blocks" do let :product do Product.create(price_cents: 3000, discount: 150, bonus_cents: 200, optional_price: 100, From 55bc8797a24523430f77723b6025337f7582e0d8 Mon Sep 17 00:00:00 2001 From: Sunny Ripert Date: Mon, 2 Feb 2026 19:41:22 +0100 Subject: [PATCH 2/7] Lint: Fix more RSpec cops --- .rubocop_todo.yml | 17 -------------- .../schema_statements_spec.rb | 2 ++ .../migration_extensions/table_spec.rb | 2 ++ spec/active_record/monetizable_spec.rb | 7 +++++- spec/helpers/action_view_extension_spec.rb | 22 +++++++++++++------ 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8893dceec..abe6d21ad 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -35,14 +35,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 25 -RSpec/BeforeAfterAll: - Exclude: - - '**/spec/spec_helper.rb' - - '**/spec/rails_helper.rb' - - '**/spec/support/**/*.rb' - - 'spec/active_record/migration_extensions/schema_statements_spec.rb' - - 'spec/active_record/migration_extensions/table_spec.rb' - # Configuration parameters: IgnoredMetadata. RSpec/DescribeClass: Exclude: @@ -58,10 +50,6 @@ RSpec/DescribeClass: RSpec/ExampleLength: Max: 24 -RSpec/ExpectInHook: - Exclude: - - 'spec/helpers/action_view_extension_spec.rb' - # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: implicit, each, example @@ -83,11 +71,6 @@ RSpec/LeadingSubject: Exclude: - 'spec/helpers/action_view_extension_spec.rb' -# Configuration parameters: . -# SupportedStyles: have_received, receive -RSpec/MessageSpies: - EnforcedStyle: receive - # Configuration parameters: AllowSubject. RSpec/MultipleMemoizedHelpers: Max: 11 diff --git a/spec/active_record/migration_extensions/schema_statements_spec.rb b/spec/active_record/migration_extensions/schema_statements_spec.rb index 61ae1ceab..42f83e7ef 100644 --- a/spec/active_record/migration_extensions/schema_statements_spec.rb +++ b/spec/active_record/migration_extensions/schema_statements_spec.rb @@ -6,12 +6,14 @@ class Item < ActiveRecord::Base; end describe MoneyRails::ActiveRecord::MigrationExtensions::SchemaStatements do + # rubocop:disable RSpec/BeforeAfterAll before :all do @connection = ActiveRecord::Base.connection @connection.drop_table :items if @connection.table_exists? :items @connection.create_table :items @connection.send :extend, described_class end + # rubocop:enable RSpec/BeforeAfterAll describe "add_money" do before do diff --git a/spec/active_record/migration_extensions/table_spec.rb b/spec/active_record/migration_extensions/table_spec.rb index 483238a7a..da543442c 100644 --- a/spec/active_record/migration_extensions/table_spec.rb +++ b/spec/active_record/migration_extensions/table_spec.rb @@ -6,10 +6,12 @@ class Item < ActiveRecord::Base; end describe MoneyRails::ActiveRecord::MigrationExtensions::SchemaStatements do + # rubocop:disable RSpec/BeforeAfterAll before :all do @connection = ActiveRecord::Base.connection @connection.send :extend, described_class end + # rubocop:enable RSpec/BeforeAfterAll describe "money" do before do diff --git a/spec/active_record/monetizable_spec.rb b/spec/active_record/monetizable_spec.rb index cac539e07..eba671405 100644 --- a/spec/active_record/monetizable_spec.rb +++ b/spec/active_record/monetizable_spec.rb @@ -920,9 +920,14 @@ def assert_monetized_attributes(monetized_attributes, expected_attributes) context "when allow_nil options is set" do let(:options) { { allow_nil: true } } + before do + allow(default_currency_lambda).to receive(:read_currency) + end + it "does not attempt to read the fallback default currency" do - expect(default_currency_lambda).not_to receive(:read_currency) read_monetized + + expect(default_currency_lambda).not_to have_receive(:read_currency) end end end diff --git a/spec/helpers/action_view_extension_spec.rb b/spec/helpers/action_view_extension_spec.rb index 508b5b98e..ce17b0a97 100644 --- a/spec/helpers/action_view_extension_spec.rb +++ b/spec/helpers/action_view_extension_spec.rb @@ -32,7 +32,7 @@ let(:money_object) { Money.new(12500) } let(:options) { {} } - subject { helper.humanized_money money_object, options } + subject(:humanized_money) { helper.humanized_money money_object, options } it { is_expected.to be_a String } it { is_expected.not_to include Money.default_currency.symbol } @@ -48,10 +48,13 @@ let(:options) { true } before(:each) do - expect(helper).to receive(:warn) + allow(helper).to receive(:warn) end - it { is_expected.to include Money.default_currency.symbol } + it do + expect(humanized_money).to include Money.default_currency.symbol + expect(helper).to have_received(:warn) + end end context "with a currency with an alternate symbol" do @@ -82,7 +85,9 @@ describe "#money_without_cents" do let(:options) { {} } - subject { helper.money_without_cents Money.new(12500), options } + subject(:money_without_cents) do + helper.money_without_cents Money.new(12500), options + end it { is_expected.to be_a String } it { is_expected.not_to include Money.default_currency.symbol } @@ -91,11 +96,14 @@ context "with deprecated symbol" do let(:options) { true } - before(:each) do - expect(helper).to receive(:warn) + before do + allow(helper).to receive(:warn) end - it { is_expected.to include Money.default_currency.symbol } + it do + expect(money_without_cents).to include Money.default_currency.symbol + expect(helper).to have_received(:warn) + end end end From 75ccf659d073309bb29a1ea0a8cadd418a019b08 Mon Sep 17 00:00:00 2001 From: Sunny Ripert Date: Mon, 2 Feb 2026 19:42:57 +0100 Subject: [PATCH 3/7] RSpec/HookArgument --- .rubocop_todo.yml | 9 --------- spec/active_record/monetizable_spec.rb | 8 ++++---- spec/helpers/action_view_extension_spec.rb | 2 +- spec/support/database_cleaner.rb | 4 ++-- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index abe6d21ad..25eea45eb 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -50,15 +50,6 @@ RSpec/DescribeClass: RSpec/ExampleLength: Max: 24 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: implicit, each, example -RSpec/HookArgument: - Exclude: - - 'spec/active_record/monetizable_spec.rb' - - 'spec/helpers/action_view_extension_spec.rb' - - 'spec/support/database_cleaner.rb' - # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: single_line_only, single_statement_only, disallow, require_implicit diff --git a/spec/active_record/monetizable_spec.rb b/spec/active_record/monetizable_spec.rb index eba671405..bae14168b 100644 --- a/spec/active_record/monetizable_spec.rb +++ b/spec/active_record/monetizable_spec.rb @@ -781,7 +781,7 @@ def assert_monetized_attributes(monetized_attributes, expected_attributes) # TODO: these specs should mock locale_backend with expected values # instead of manipulating it directly context "with an Italian locale" do - around(:each) do |example| + around do |example| I18n.with_locale(:it) do example.run end @@ -810,7 +810,7 @@ def assert_monetized_attributes(monetized_attributes, expected_attributes) end context "when using :currency locale backend" do - around(:each) do |example| + around do |example| Money.locale_backend = :currency example.run ensure @@ -880,7 +880,7 @@ def assert_monetized_attributes(monetized_attributes, expected_attributes) end context "with preserve_user_input set" do - around(:each) do |example| + around do |example| MoneyRails::Configuration.preserve_user_input = true example.run MoneyRails::Configuration.preserve_user_input = false @@ -909,7 +909,7 @@ def assert_monetized_attributes(monetized_attributes, expected_attributes) let(:read_monetized) { service.read_monetized(:discount, :discount_cents, options) } - around(:each) do |example| + around do |example| service # Instantiate instance which relies on Money.default_currency original_default_currency = Money.default_currency Money.default_currency = -> { default_currency_lambda.read_currency } diff --git a/spec/helpers/action_view_extension_spec.rb b/spec/helpers/action_view_extension_spec.rb index ce17b0a97..ef31c35f4 100644 --- a/spec/helpers/action_view_extension_spec.rb +++ b/spec/helpers/action_view_extension_spec.rb @@ -47,7 +47,7 @@ context "with deprecated symbol" do let(:options) { true } - before(:each) do + before do allow(helper).to receive(:warn) end diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb index 5e960b348..3c3a82443 100644 --- a/spec/support/database_cleaner.rb +++ b/spec/support/database_cleaner.rb @@ -11,11 +11,11 @@ end end - config.before :each do + config.before do DatabaseCleaner.start end - config.after :each do + config.after do DatabaseCleaner.clean end end From 728e6a1b3df79d8452273ffc95e609ce17b3ffda Mon Sep 17 00:00:00 2001 From: Sunny Ripert Date: Thu, 5 Feb 2026 21:56:43 +0100 Subject: [PATCH 4/7] Spec fix --- spec/active_record/monetizable_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/active_record/monetizable_spec.rb b/spec/active_record/monetizable_spec.rb index 29dd06755..6b16aef6b 100644 --- a/spec/active_record/monetizable_spec.rb +++ b/spec/active_record/monetizable_spec.rb @@ -927,7 +927,7 @@ def assert_monetized_attributes(monetized_attributes, expected_attributes) it "does not attempt to read the fallback default currency" do read_monetized - expect(default_currency_lambda).not_to have_receive(:read_currency) + expect(default_currency_lambda).not_to have_received(:read_currency) end end end From d780ab5eeb9be95db6e845ac2dae7aad936a5c5c Mon Sep 17 00:00:00 2001 From: Sunny Ripert Date: Thu, 5 Feb 2026 22:07:39 +0100 Subject: [PATCH 5/7] Lint: Fix even more RSpec cops Fixes the following cops: - RSpec/ImplicitSubject - RSpec/LeadingSubject - RSpec/NotToNot - RSpec/Output - RSpec/PredicateMatcher - RSpec/ReceiveMessages - RSpec/ReturnFromStub - RSpec/SharedContext --- .rubocop.yml | 11 +++++ .rubocop_todo.yml | 50 ---------------------- spec/active_record/monetizable_spec.rb | 10 +++-- spec/configuration_spec.rb | 2 +- spec/helpers/action_view_extension_spec.rb | 12 +++--- spec/money_spec.rb | 6 ++- spec/test_helpers_spec.rb | 20 ++++----- 7 files changed, 39 insertions(+), 72 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index d1dd6d167..a38a5610d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -54,6 +54,17 @@ RSpec/MultipleExpectations: # Do not limit the amount of expectations in a spec Enabled: false +RSpec/Output: + Exclude: + - "spec/dummy/**/*" + +RSpec/PredicateMatcher: + # Do not force calling: + # expect(money).to be_serialize(…) + # Instead of the more explicit: + # expect(money.serialize?(…)).to be_truthy + Enabled: false + # Style Style/ClassAndModuleChildren: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 0417373fc..6b8de40ac 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -50,18 +50,6 @@ RSpec/DescribeClass: RSpec/ExampleLength: Max: 24 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: single_line_only, single_statement_only, disallow, require_implicit -RSpec/ImplicitSubject: - Exclude: - - 'spec/test_helpers_spec.rb' - -# This cop supports safe autocorrection (--autocorrect). -RSpec/LeadingSubject: - Exclude: - - 'spec/helpers/action_view_extension_spec.rb' - # Configuration parameters: AllowSubject. RSpec/MultipleMemoizedHelpers: Max: 11 @@ -76,44 +64,6 @@ RSpec/NoExpectationExample: Exclude: - 'spec/active_record/monetizable_spec.rb' -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: not_to, to_not -RSpec/NotToNot: - Exclude: - - 'spec/active_record/monetizable_spec.rb' - - 'spec/configuration_spec.rb' - -# This cop supports unsafe autocorrection (--autocorrect-all). -RSpec/Output: - Exclude: - - 'spec/dummy/config/boot.rb' - -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: Strict, EnforcedStyle, AllowedExplicitMatchers. -# SupportedStyles: inflected, explicit -RSpec/PredicateMatcher: - Exclude: - - 'spec/active_job/money_serializer_spec.rb' - - 'spec/active_record/monetizable_spec.rb' - -# This cop supports unsafe autocorrection (--autocorrect-all). -RSpec/ReceiveMessages: - Exclude: - - 'spec/money_spec.rb' - -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: and_return, block -RSpec/ReturnFromStub: - Exclude: - - 'spec/active_record/monetizable_spec.rb' - -# This cop supports safe autocorrection (--autocorrect). -RSpec/SharedContext: - Exclude: - - 'spec/test_helpers_spec.rb' - # Configuration parameters: IgnoreNameless, IgnoreSymbolicNames. RSpec/VerifiedDoubles: Exclude: diff --git a/spec/active_record/monetizable_spec.rb b/spec/active_record/monetizable_spec.rb index 6b16aef6b..2110dab72 100644 --- a/spec/active_record/monetizable_spec.rb +++ b/spec/active_record/monetizable_spec.rb @@ -482,7 +482,7 @@ def assert_monetized_attributes(monetized_attributes, expected_attributes) end it "doesn't raise exception if validation is used and nil is not allowed" do - expect { product.price = nil }.to_not raise_error + expect { product.price = nil }.not_to raise_error end it "doesn't save nil values if validation is used and nil is not allowed" do @@ -758,8 +758,12 @@ def assert_monetized_attributes(monetized_attributes, expected_attributes) end it "allows currency column postfix to be blank" do - allow(MoneyRails::Configuration).to receive(:currency_column) { { postfix: nil, column_name: "currency" } } - expect(dummy_product_with_nil_currency.price.currency).to eq(Money::Currency.find(:gbp)) + allow(MoneyRails::Configuration) + .to receive(:currency_column) + .and_return({ postfix: nil, column_name: "currency" }) + + expect(dummy_product_with_nil_currency.price.currency) + .to eq(Money::Currency.find(:gbp)) end it "updates inferred currency column based on currency column postfix" do diff --git a/spec/configuration_spec.rb b/spec/configuration_spec.rb index 83b66986c..59baa78ec 100644 --- a/spec/configuration_spec.rb +++ b/spec/configuration_spec.rb @@ -107,7 +107,7 @@ expect do MoneyRails.default_currency = :jpy - end.to_not raise_error + end.not_to raise_error expect(MoneyRails.amount_column[:postfix]).to eq("_cents") diff --git a/spec/helpers/action_view_extension_spec.rb b/spec/helpers/action_view_extension_spec.rb index ef31c35f4..0ba00558f 100644 --- a/spec/helpers/action_view_extension_spec.rb +++ b/spec/helpers/action_view_extension_spec.rb @@ -29,11 +29,11 @@ end describe "#humanized_money" do + subject(:humanized_money) { helper.humanized_money money_object, options } + let(:money_object) { Money.new(12500) } let(:options) { {} } - subject(:humanized_money) { helper.humanized_money money_object, options } - it { is_expected.to be_a String } it { is_expected.not_to include Money.default_currency.symbol } it { is_expected.not_to include Money.default_currency.decimal_mark } @@ -83,12 +83,12 @@ end describe "#money_without_cents" do - let(:options) { {} } - subject(:money_without_cents) do helper.money_without_cents Money.new(12500), options end + let(:options) { {} } + it { is_expected.to be_a String } it { is_expected.not_to include Money.default_currency.symbol } it { is_expected.not_to include Money.default_currency.decimal_mark } @@ -117,10 +117,10 @@ end describe "#money_only_cents" do - let(:monetizable_object) { Money.new(125_00) } - subject { helper.money_only_cents monetizable_object } + let(:monetizable_object) { Money.new(125_00) } + it { is_expected.to eq "00" } context "with a non-money object" do diff --git a/spec/money_spec.rb b/spec/money_spec.rb index b52b889a3..05d2b2de7 100644 --- a/spec/money_spec.rb +++ b/spec/money_spec.rb @@ -24,8 +24,10 @@ it "gives priority to original defaults" do allow(Money).to receive(:orig_default_formatting_rules).and_return(symbol: "£") - allow(MoneyRails::Configuration).to receive(:symbol).and_return("€") - allow(MoneyRails::Configuration).to receive(:default_format).and_return(symbol: "€") + allow(MoneyRails::Configuration).to receive_messages( + symbol: "€", + default_format: { symbol: "€" }, + ) expect(Money.default_formatting_rules).to include(symbol: "£") end diff --git a/spec/test_helpers_spec.rb b/spec/test_helpers_spec.rb index d779ec292..60ba750db 100644 --- a/spec/test_helpers_spec.rb +++ b/spec/test_helpers_spec.rb @@ -14,29 +14,29 @@ end describe "monetize matcher" do - shared_context "with monetize matcher" do + shared_examples "with monetize matcher" do it "matches model attribute without a '_cents' suffix by default" do - is_expected.to monetize(:price) + expect(subject).to monetize(:price) end it "matches model attribute specified by :as chain" do - is_expected.to monetize(:discount).as(:discount_value) + expect(subject).to monetize(:discount).as(:discount_value) end it "matches model attribute with nil value specified by :allow_nil chain" do - is_expected.to monetize(:optional_price).allow_nil + expect(subject).to monetize(:optional_price).allow_nil end it "matches nullable model attribute when tested instance has a non-nil value" do - is_expected.to monetize(:optional_price).allow_nil + expect(subject).to monetize(:optional_price).allow_nil end it "matches model attribute with currency specified by :with_currency chain" do - is_expected.to monetize(:bonus).with_currency(:gbp) + expect(subject).to monetize(:bonus).with_currency(:gbp) end it "matches model attribute with currency attribute specified by :with_model_currency chain" do - is_expected.to( + expect(subject).to( monetize(:sale_price_amount) .as(:sale_price) .with_model_currency(:sale_price_currency_code), @@ -44,15 +44,15 @@ end it "does not match non existed attribute" do - is_expected.not_to monetize(:price_fake) + expect(subject).not_to monetize(:price_fake) end it "does not match wrong currency iso" do - is_expected.not_to monetize(:bonus).with_currency(:usd) + expect(subject).not_to monetize(:bonus).with_currency(:usd) end it "does not match wrong money attribute name" do - is_expected.not_to monetize(:bonus).as(:bonussss) + expect(subject).not_to monetize(:bonus).as(:bonussss) end end From a9a4c0f1133927512150ae130791ae9e136a681f Mon Sep 17 00:00:00 2001 From: Sunny Ripert Date: Thu, 5 Feb 2026 22:12:25 +0100 Subject: [PATCH 6/7] And more! --- .rubocop_todo.yml | 11 ----------- spec/active_record/monetizable_spec.rb | 13 +++++++------ 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 6b8de40ac..88c71d3c3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -58,17 +58,6 @@ RSpec/MultipleMemoizedHelpers: RSpec/NestedGroups: Max: 5 -# Configuration parameters: AllowedPatterns. -# AllowedPatterns: ^expect_, ^assert_ -RSpec/NoExpectationExample: - Exclude: - - 'spec/active_record/monetizable_spec.rb' - -# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames. -RSpec/VerifiedDoubles: - Exclude: - - 'spec/active_record/monetizable_spec.rb' - # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, AllowRBSInlineAnnotation, AllowCopDirectives, AllowedPatterns, SplitStrings. # URISchemes: http, https diff --git a/spec/active_record/monetizable_spec.rb b/spec/active_record/monetizable_spec.rb index 2110dab72..ed092672f 100644 --- a/spec/active_record/monetizable_spec.rb +++ b/spec/active_record/monetizable_spec.rb @@ -652,7 +652,7 @@ def assert_monetized_attributes(monetized_attributes, expected_attributes) context "with a column with model currency" do it "has default currency if not specified" do product = Product.create(sale_price_amount: 1234) - product.sale_price.currency.to_s == "USD" + expect(product.sale_price.currency.to_s).to eq("USD") end it "is overridden by instance currency column" do @@ -909,7 +909,12 @@ def assert_monetized_attributes(monetized_attributes, expected_attributes) let(:service) do Service.create(discount_cents: nil) end - let(:default_currency_lambda) { double("Default Currency Fallback") } + + # rubocop:disable RSpec/VerifiedDoubles + let(:default_currency_lambda) do + double :default_fallback, read_currency: nil + end + # rubocop:enable RSpec/VerifiedDoubles let(:read_monetized) { service.read_monetized(:discount, :discount_cents, options) } @@ -924,10 +929,6 @@ def assert_monetized_attributes(monetized_attributes, expected_attributes) context "when allow_nil options is set" do let(:options) { { allow_nil: true } } - before do - allow(default_currency_lambda).to receive(:read_currency) - end - it "does not attempt to read the fallback default currency" do read_monetized From a4edc5b88d10690d7f9316167cbca7ba6e74f0dc Mon Sep 17 00:00:00 2001 From: Sunny Ripert Date: Thu, 5 Feb 2026 22:24:32 +0100 Subject: [PATCH 7/7] Lint: Fix last RSpec cops --- .rubocop.yml | 1 + .rubocop_todo.yml | 11 ---- spec/{ => money_rails}/configuration_spec.rb | 57 ++++++++++++++------ spec/money_spec.rb | 2 +- 4 files changed, 43 insertions(+), 28 deletions(-) rename spec/{ => money_rails}/configuration_spec.rb (75%) diff --git a/.rubocop.yml b/.rubocop.yml index a38a5610d..c56842b01 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -49,6 +49,7 @@ RSpec/DescribedClass: Exclude: # Prefer Money.new(…) to described_class.new(…) - "spec/mongoid/mongoid_spec.rb" + - "spec/money_spec.rb" RSpec/MultipleExpectations: # Do not limit the amount of expectations in a spec diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 88c71d3c3..44f35e53a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -35,17 +35,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 25 -# Configuration parameters: IgnoredMetadata. -RSpec/DescribeClass: - Exclude: - - '**/spec/features/**/*' - - '**/spec/requests/**/*' - - '**/spec/routing/**/*' - - '**/spec/system/**/*' - - '**/spec/views/**/*' - - 'spec/configuration_spec.rb' - - 'spec/money_spec.rb' - # Configuration parameters: CountAsOne. RSpec/ExampleLength: Max: 24 diff --git a/spec/configuration_spec.rb b/spec/money_rails/configuration_spec.rb similarity index 75% rename from spec/configuration_spec.rb rename to spec/money_rails/configuration_spec.rb index 59baa78ec..4d6c08486 100644 --- a/spec/configuration_spec.rb +++ b/spec/money_rails/configuration_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -describe "configuration" do +describe MoneyRails::Configuration do describe "initializer" do it "sets default currency" do expect(Money.default_currency).to eq(Money::Currency.new(:eur)) @@ -17,25 +17,50 @@ expect(Money.ca_dollar(100).bank.get_rate("CAD", "USD")).to eq(0.803115) end - it "sets no_cents_if_whole value for formatted output globally" do - # Enable formatting to depend only on currency (to avoid default symbols for :en) - Money.locale_backend = :currency + context "with currency backend" do + let(:value) { Money.new(123_456_00, "EUR") } + let(:mark) { Money::Currency.find(:eur).decimal_mark } - value = Money.new(12345600, "EUR") - mark = Money::Currency.find(:eur).decimal_mark - expect(value.format).to match(/#{mark}/) + around do |example| + # Enable formatting to depend only on currency (to avoid default symbols for :en) + Money.locale_backend = :currency + example.call + Money.locale_backend = :i18n + end - MoneyRails.no_cents_if_whole = true - expect(value.format).not_to match(/#{mark}/) - expect(value.format(no_cents_if_whole: false)).to match(/#{mark}/) + context "with no cents if whole nil" do + before do + MoneyRails.no_cents_if_whole = nil + end - MoneyRails.no_cents_if_whole = false - expect(value.format).to match(/#{mark}/) - expect(value.format(no_cents_if_whole: true)).not_to match(/#{mark}/) + it { expect(value.format).to include(mark) } + end - # Reset global settings - MoneyRails.no_cents_if_whole = nil - Money.locale_backend = :i18n + context "with no cents if whole enabled" do + around do |example| + MoneyRails.no_cents_if_whole = true + example.call + MoneyRails.no_cents_if_whole = nil + end + + it do + expect(value.format).not_to include(mark) + expect(value.format(no_cents_if_whole: false)).to include(mark) + end + end + + context "with no cents if whole disabled" do + around do |example| + MoneyRails.no_cents_if_whole = false + example.call + MoneyRails.no_cents_if_whole = nil + end + + it do + expect(value.format).to include(mark) + expect(value.format(no_cents_if_whole: true)).not_to include(mark) + end + end end it "sets symbol for formatted output globally" do diff --git a/spec/money_spec.rb b/spec/money_spec.rb index 05d2b2de7..0f4e764a6 100644 --- a/spec/money_spec.rb +++ b/spec/money_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -describe "Money overrides" do +describe Money do describe ".default_formatting_rules" do it "uses defauts set as individual options" do allow(MoneyRails::Configuration).to receive(:symbol).and_return("£")