TypeError: can't define singleton
Created by: zhisme
Subject of the issue
Try to mock class not by an object, but by a symbol and get very uninformative error message. Maybe we can improve such behaviour and leave for programmer better error message, like
Tried to mock symbol, but object expected.
Of course we can go to stackoverflow with some googling, but on my opinion this error message very unfriendly and error-phone.
Your environment
- Ruby version: 2.7.0
- rspec-mocks version: 2.14.6
Steps to reproduce
allow(:subject).to receive(:foo).and_return(:baz)
Expected behavior
Some error raised
raise ArgumentError, 'Passed not an object'
Actual behavior
Failure/Error: allow(:action).to receive(:foo).and_return(:baz)
TypeError:
can't define singleton