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

allow_any_instance_of(Object).to receive(:sleep) failure #123

Open
rdh opened this issue Jun 14, 2022 · 4 comments
Open

allow_any_instance_of(Object).to receive(:sleep) failure #123

rdh opened this issue Jun 14, 2022 · 4 comments

Comments

@rdh
Copy link

rdh commented Jun 14, 2022

After adding buildkite-test_collector to our Gemfile, specs that stub sleep in this way...

allow_any_instance_of(Object).to receive(:sleep)

... have begun failing with this error message...

Failure/Error: allow_any_instance_of(Object).to receive(:sleep)
       Using `any_instance` to stub a method (sleep) that has been defined on a prepended module (Buildkite::TestCollector::Object::CustomObjectSleep) is not supported.

... under rspec (3.10.0) and rspec-rails (5.0.0)

@gchan
Copy link
Contributor

gchan commented Jun 21, 2022

When we initially built the collector, we didn't consider use cases where sleep is stubbed this way because allow_any_instance_of is generally not a recommended practice any more.

We may look to support this better in the future but you could try stubbing the class under test like this:

allow_any_instance_of(TheClassUnderTest).to receive(:sleep)

Another customer encountered this same problem and this resolved their issue.

Thanks!

@JuanitoFatas
Copy link
Member

GitLab had a similar issue and their solution is to use a custom matcher, maybe this may work for you?

@gchan
Copy link
Contributor

gchan commented Jun 21, 2022

@rdh 👆️

@rdh
Copy link
Author

rdh commented Jun 30, 2022

Just a follow-up. The failures were easily resolved with...

allow_any_instance_of(TheClassUnderTest).to receive(:sleep)

Would still be ideal if this gem "just worked" as a drop-in to legacy repos, but pretty minor.

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

No branches or pull requests

3 participants