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

TypeError: can't define singleton #1356

Closed
zhisme opened this issue Dec 3, 2020 · 2 comments · Fixed by #1357
Closed

TypeError: can't define singleton #1356

zhisme opened this issue Dec 3, 2020 · 2 comments · Fixed by #1357

Comments

@zhisme
Copy link
Contributor

zhisme commented Dec 3, 2020

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
@pirj
Copy link
Member

pirj commented Dec 3, 2020

Well noticed. I've been making this mistake a couple of times as well.
A pull request is welcome.

@zhisme
Copy link
Contributor Author

zhisme commented Dec 3, 2020

great, I will take care of implementation then

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

Successfully merging a pull request may close this issue.

2 participants