Cannot proxy frozen objects, rspec-mocks relies on proxies for method stubbing and expectations.
Created by: Loschcode
Subject of the issue
I moved from rspec-mocks
3.9.0 to 3.10.0 recently and it breaks several tests that were working before. Typically, it'll throw this message Cannot proxy frozen objects, rspec-mocks relies on proxies for method stubbing and expectations.
Your environment
- Ruby version: ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-darwin21]
- rspec-mocks version: 3.10.0
Steps to reproduce
After investigating, it occurs systematically when I use allow_any_instance_of
against a model in Rails. I couldn't find anyone talking about it precisely anywhere, which's odd.
For example, if I do
allow_any_instance_of(Identity).to receive(:destroy_hook_service)
And then call my subject
it'll crash. I know we should avoid doing that and prefer stubbing a precise record, but from time to time you really want to cover all the instances of the classes. In this example, I can't actually target a specific identity
, it's checking global destruction of some sort.
Expected behavior
It stubs/mocks some methods
Actual behavior
It crashes.