# Enable\_stub raise can't modify frozen class error

**URL:** <https://discourse.dry-rb.org/t/enable-stub-raise-cant-modify-frozen-class-error/1632>\
**Category:** dry-system\
**Created:** [March 23, 2023, 5:41pm UTC](https://discourse.dry-rb.org/t/enable-stub-raise-cant-modify-frozen-class-error/1632 "2023-03-23T17:41:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tyflomate](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/tyflomate/32/746_2.png) [@Tyflomate](https://discourse.dry-rb.org/u/Tyflomate)\
**Post date:** [March 23, 2023, 5:41pm UTC](https://discourse.dry-rb.org/t/enable-stub-raise-cant-modify-frozen-class-error/1632/1 "2023-03-23T17:41:09Z")

</div>

Hello,

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

```auto
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](https://paste.bingner.com/paste/y752w)  
And my container initializer: [r3zak - Ghostbin](https://paste.bingner.com/paste/r3zak).  
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

---

<div class="post-metadata">

**Author:** ![Tyflomate](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/tyflomate/32/746_2.png) [@Tyflomate](https://discourse.dry-rb.org/u/Tyflomate)\
**Post date:** [March 24, 2023, 4:40pm UTC](https://discourse.dry-rb.org/t/enable-stub-raise-cant-modify-frozen-class-error/1632/2 "2023-03-24T16:40:27Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Tyflomate](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/tyflomate/32/746_2.png) [@Tyflomate](https://discourse.dry-rb.org/u/Tyflomate)\
**Post date:** [March 30, 2023, 12:41pm UTC](https://discourse.dry-rb.org/t/enable-stub-raise-cant-modify-frozen-class-error/1632/3 "2023-03-30T12:41:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![timriley](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/timriley/32/25_2.png) [@timriley](https://discourse.dry-rb.org/u/timriley)\
**Post date:** [March 31, 2023, 7:38am UTC](https://discourse.dry-rb.org/t/enable-stub-raise-cant-modify-frozen-class-error/1632/4 "2023-03-31T07:38:04Z")

</div>

The related issue discussion, just for reference: [Enable\_stub raise can't modify frozen class error · Issue #265 · dry-rb/dry-system · GitHub](https://github.com/dry-rb/dry-system/issues/265)
