From 4da34f7b1decb61eef35fc92cb3c88ab8add1da1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Pacana?= Date: Sun, 17 May 2026 12:15:53 +0200 Subject: [PATCH] Use minitest-stub-const for temporary constant stubbing - Replaces the ad-hoc `with_const` helper in test_factories.rb with `Object.stub_const`, keeping the block-scoped restore semantics without rolling our own. --- Gemfile | 1 + Gemfile.lock | 3 +++ test/test_factories.rb | 9 +-------- test/test_helper.rb | 1 + 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Gemfile b/Gemfile index 8a018f3..cf820fb 100644 --- a/Gemfile +++ b/Gemfile @@ -10,6 +10,7 @@ gem "rake" gem "m" gem "minitest" gem "minitest-mock" +gem "minitest-stub-const" gem "mutant-minitest" gem "concurrent-ruby" gem "pg-ephemeral" diff --git a/Gemfile.lock b/Gemfile.lock index c0b2d35..7f22ade 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -51,6 +51,7 @@ GEM drb (~> 2.0) prism (~> 1.5) minitest-mock (5.27.0) + minitest-stub-const (0.6) mutant (0.16.3) diff-lcs (>= 1.6, < 3) irb (~> 1.15) @@ -126,6 +127,7 @@ DEPENDENCIES m minitest minitest-mock + minitest-stub-const mutant-minitest pg-ephemeral rake @@ -155,6 +157,7 @@ CHECKSUMS m (1.7.0) sha256=058f793da8150c51353cc59366ffae7774683e868bede3c78f81d920fb9d633a minitest (6.0.6) sha256=153ea36d1d987a62942382b61075745042a2b3123b1cd48f4c3675af9cc7d6f1 minitest-mock (5.27.0) sha256=7040ed7185417a966920987eaa6eaf1be4ea1fc5b25bb03ff4703f98564a55b0 + minitest-stub-const (0.6) sha256=b39f34dd6b8e7045fcc36820083aceaa68075318e4c4f365b12f11bd5f34b279 mutant (0.16.3) sha256=7e10fb09b80a78d82f8e38283fc1e4d562cbb1392451e2a21611ea2bc44b5023 mutant-minitest (0.16.3) sha256=504d110c1bd503528a7e57a4f062960e571bba4e3939e4a66ddc0f75d2071d90 mutex_m (0.3.0) sha256=cfcb04ac16b69c4813777022fdceda24e9f798e48092a2b817eb4c0a782b0751 diff --git a/test/test_factories.rb b/test/test_factories.rb index f191d47..d7f0e6d 100644 --- a/test/test_factories.rb +++ b/test/test_factories.rb @@ -21,7 +21,7 @@ module En57 end def test_for_active_record_round_trips_with_custom_model - with_const(:DasModel, Class.new(ActiveRecord::Base)) do + Object.stub_const(:DasModel, Class.new(ActiveRecord::Base)) do assert_round_trip(EventStore.for_active_record(DasModel)) end end @@ -41,13 +41,6 @@ module En57 private - def with_const(name, value) - Object.const_set(name, value) - yield - ensure - Object.__send__(:remove_const, name) - end - def assert_round_trip(event_store) event = Event.new(type: "FactoryTested") diff --git a/test/test_helper.rb b/test/test_helper.rb index f707f91..28c0048 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,6 +2,7 @@ require "minitest/autorun" require "minitest/mock" +require "minitest/stub_const" require "mutant/minitest/coverage" # optional dependencies -- 2.51.2