Skip to content

Commit 4da34f7

Browse files
committed
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.
1 parent fc21077 commit 4da34f7

4 files changed

Lines changed: 6 additions & 8 deletions

File tree

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ gem "rake"
1010
gem "m"
1111
gem "minitest"
1212
gem "minitest-mock"
13+
gem "minitest-stub-const"
1314
gem "mutant-minitest"
1415
gem "concurrent-ruby"
1516
gem "pg-ephemeral"

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ GEM
5151
drb (~> 2.0)
5252
prism (~> 1.5)
5353
minitest-mock (5.27.0)
54+
minitest-stub-const (0.6)
5455
mutant (0.16.3)
5556
diff-lcs (>= 1.6, < 3)
5657
irb (~> 1.15)
@@ -126,6 +127,7 @@ DEPENDENCIES
126127
m
127128
minitest
128129
minitest-mock
130+
minitest-stub-const
129131
mutant-minitest
130132
pg-ephemeral
131133
rake
@@ -155,6 +157,7 @@ CHECKSUMS
155157
m (1.7.0) sha256=058f793da8150c51353cc59366ffae7774683e868bede3c78f81d920fb9d633a
156158
minitest (6.0.6) sha256=153ea36d1d987a62942382b61075745042a2b3123b1cd48f4c3675af9cc7d6f1
157159
minitest-mock (5.27.0) sha256=7040ed7185417a966920987eaa6eaf1be4ea1fc5b25bb03ff4703f98564a55b0
160+
minitest-stub-const (0.6) sha256=b39f34dd6b8e7045fcc36820083aceaa68075318e4c4f365b12f11bd5f34b279
158161
mutant (0.16.3) sha256=7e10fb09b80a78d82f8e38283fc1e4d562cbb1392451e2a21611ea2bc44b5023
159162
mutant-minitest (0.16.3) sha256=504d110c1bd503528a7e57a4f062960e571bba4e3939e4a66ddc0f75d2071d90
160163
mutex_m (0.3.0) sha256=cfcb04ac16b69c4813777022fdceda24e9f798e48092a2b817eb4c0a782b0751

test/test_factories.rb

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_for_active_record_round_trips_with_default_model
2121
end
2222

2323
def test_for_active_record_round_trips_with_custom_model
24-
with_const(:DasModel, Class.new(ActiveRecord::Base)) do
24+
Object.stub_const(:DasModel, Class.new(ActiveRecord::Base)) do
2525
assert_round_trip(EventStore.for_active_record(DasModel))
2626
end
2727
end
@@ -41,13 +41,6 @@ def test_event_store_does_not_conflict_with_public_schema_tables
4141

4242
private
4343

44-
def with_const(name, value)
45-
Object.const_set(name, value)
46-
yield
47-
ensure
48-
Object.__send__(:remove_const, name)
49-
end
50-
5144
def assert_round_trip(event_store)
5245
event = Event.new(type: "FactoryTested")
5346

test/test_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require "minitest/autorun"
44
require "minitest/mock"
5+
require "minitest/stub_const"
56
require "mutant/minitest/coverage"
67

78
# optional dependencies

0 commit comments

Comments
 (0)