Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

ArgumentError: Cannot proxy frozen objects, rspec-mocks relies on proxies for method stubbing and expectations for boolean objects #1270

Closed
bestwebua opened this issue Dec 30, 2020 · 4 comments

Comments

@bestwebua
Copy link

Subject of the issue

Stub for boolean object raises ArgumentError: Cannot proxy frozen objects, rspec-mocks relies on proxies for method stubbing and expectations.

Your environment

  • Ruby version: ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin19]
  • rspec-expectations version: 3.10.1

Steps to reproduce

RSpec.describe 'Example' do
  let(:some_object) { true }
  let(:args) { (0..5).to_a }

  it do
    expect(some_object).to receive(:some_method).with(args)
    some_object.some_method(args)
  end
end

Expected behavior

bundle exec rspec spec/example_spec.rb

Example
  is expected to receive some_method([0, 1, 2, 3, 4, 5]) 1 time

Finished in 0.00696 seconds (files took 0.52326 seconds to load)
1 example, 0 failures

Actual behavior

bundle exec rspec spec/example_spec.rb

Example
  is expected to receive some_method (FAILED - 1)

Failures:

  1) Example is expected to receive some_method
     Failure/Error: expect(some_object).to receive(:some_method).with(args)
     
     ArgumentError:
       Cannot proxy frozen objects, rspec-mocks relies on proxies for method stubbing and expectations.
     # ./spec/example_spec.rb:6:in `block (2 levels) in <top (required)>'

Finished in 0.00769 seconds (files took 0.54186 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/example_spec.rb:5 # Example is expected to receive some_method
@bestwebua bestwebua changed the title ArgumentError: Cannot proxy frozen objects, rspec-mocks relies on proxies for method stubbing and expectations ArgumentError: Cannot proxy frozen objects, rspec-mocks relies on proxies for method stubbing and expectations for boolean objects Dec 30, 2020
@pirj
Copy link
Member

pirj commented Dec 30, 2020

Thanks for reporting.
I can reproduce this synthetic example.
Wondering what is the real use case?

@JonRowe JonRowe closed this as completed Dec 30, 2020
@bestwebua
Copy link
Author

@JonRowe Is it an expected behaviour?

@JonRowe
Copy link
Member

JonRowe commented Dec 30, 2020

Yes.

This is a deliberate bug fix for rspec-mocks (not rspec-expectations, theres no stubbing here) that was released (rspec/rspec-mocks#1357), because we cannot modify frozen objects to proxy them, you would normally get a cryptic TypeError which we prevent by raising an ArgumentError before it can happen.

@bestwebua
Copy link
Author

@JonRowe Now it's clear for me. Thanks and Happy new year!!! 🎅

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants