Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stub by id #619

Open
nhorton opened this issue Sep 14, 2023 · 0 comments
Open

Stub by id #619

nhorton opened this issue Sep 14, 2023 · 0 comments

Comments

@nhorton
Copy link

nhorton commented Sep 14, 2023

I filed #618 a few minutes ago and realized that my other big need might actually solve the same issue.

Right now, I overuse any_instance because often the object that I want to stub is an ActiveRecord object, but the instance the code I am testing will run against is not one I can access and stub trivially. A really simple motivating example is ActiveJob - you often pass ID's there and let the job search by ID.

It would be really helpful if there was something like:

MyClass.instance_where(id: 5).expects(:foobar)

I don't care much on the instance_where syntax. An alternative would be to use matchers like:

record = MyClass.find(27)
MyClass.instance_matching(record).expects(:foobar)

ActiveRecord instances with the same id === each other (and == actually) and you could then use it other ways, like:

String.instance_matching(/my_regex/).expects(:constantize)

If I had that, I could do the "have one instance raise and the others not" needed for #618 too.

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

No branches or pull requests

2 participants