Enable_stub raise can't modify frozen class error

Hello,

I have an issue with dry-system enable_stubs method, it causes my test to fail with the following snippet:

An error occurred while loading ./spec/policies/user_policy_spec.rb.
Failure/Error: LeRegistreApi::Container.enable_stubs!

FrozenError:
  can't modify frozen Class: LeRegistreApi::Container
# /home/tyflomate/.gem/gems/dry-core-1.0.0/lib/dry/core/container/stub.rb:52:in `extend_object'
# /home/tyflomate/.gem/gems/dry-core-1.0.0/lib/dry/core/container/stub.rb:52:in `extend'
# /home/tyflomate/.gem/gems/dry-core-1.0.0/lib/dry/core/container/stub.rb:52:in `enable_stubs!'
# /home/tyflomate/.gem/gems/dry-system-1.0.1/lib/dry/system/stubs.rb:33:in `enable_stubs!'
# ./spec/rails_helper.rb:25:in `<top (required)>'
# /home/tyflomate/.gem/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /home/tyflomate/.gem/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /home/tyflomate/.gem/gems/zeitwerk-2.6.7/lib/zeitwerk/kernel.rb:38:in `require'
# ./spec/policies/user_policy_spec.rb:3:in `<top (required)>'
No examples found.


Finished in 0.00003 seconds (files took 4.4 seconds to load)
0 examples, 0 failures, 125 errors occurred outside of examples

Here is my rails_helper: y752w - Ghostbin
And my container initializer: r3zak - Ghostbin.
What is weird is that on my other computer it works correctly. I tried uninstalling all my ruby versions/gems/rbenv and reinstalling but still have the issue. I don’t know what could cause that, I hope you can help ! Thanks a lot

There’s news to this, apparently this issue also appears on my coworker computer. But we have a ci and the tests correctly runs … My coworker is on macOs, I am on ubuntu installed on a mac but the ci is running on ubuntu-latest. I also have another coworker with a mac m1 and tests runs correctly. I also wrote a dockerfile to run the tests and I have the same issue, i’m building my docker image from ruby:2.7.5. Even weirder, if i run my tests suite whith rubymine, it works correctly…

Turns out i was running my tests in development env. Dry::Rails::Railtie config.prepare got runned somehow and it finalizes the container if we are not in test env

The related issue discussion, just for reference: Enable_stub raise can't modify frozen class error · Issue #265 · dry-rb/dry-system · GitHub