Skip to content

Conversation

WesleyW
Copy link
Contributor

@WesleyW WesleyW commented Jun 27, 2023

When mocking controllers in Rspec, the class may be constructed in code, which means a class may look like #<Class:0x000000015ea185d8>, causing Object.const_source_location to fail. These should just return nil

@alexevanczuk
Copy link
Contributor

@WesleyW This looks fine, but is there a way to detect these anonymous classes and return nil explicitly rather than just rescue NameError?

@WesleyW
Copy link
Contributor Author

WesleyW commented Jun 28, 2023

@alexevanczuk I don't think so... After fiddling around a bit more, I think it's just specs not always conforming to sorbet types. I can repro my original issue by calling CodeOwnership.for_class(Class.new.new.class), but this fails the typecheck here, since klass is an anonymass class instead of a Class.

@alexevanczuk alexevanczuk merged commit e2f4e3d into rubyatscale:main Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants