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

Add support for detecting if WebMock is enabled #701

Closed
redconfetti opened this Issue May 17, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@redconfetti
Copy link

redconfetti commented May 17, 2017

Feature Request

I'm encountering a use case where we would like to check if WebMock is enabled or not.

> WebMock.enabled?
=> false
> WebMock.enable!
> WebMock.enabled?
=> true
> WebMock.disable!
> WebMock.enabled?
=> false

Use Case

The application I'm working on raises exceptions when HTTP 400+ response is received, and depending on the circumstance the exception is caught and logged with a stack trace.

When we're using WebMock, these stack traces are not needed in our logs. They're really cluttering up the TravisCI logs unnecessarily. We'd like to exclude the error or stack traces from our logs when WebMock is being used. Support for WebMock.enabled? would really help with this.

Approach

I'm thinking of making a pull request for this myself. A simple class variable boolean that is modified in WebMock.enabled! and WebMock.disabled! is all that's needed.

@@enabled = true
@bblimke

This comment has been minimized.

Copy link
Owner

bblimke commented May 17, 2017

Thanks for a well defined issue.

It all makes sense except the fact WebMock can be enabled only for some http clients.
https://github.com/bblimke/webmock#disabling-and-enabling-webmock-or-only-some-http-client-adapters

Any ideas?

@redconfetti

This comment has been minimized.

Copy link

redconfetti commented May 17, 2017

Yes. You have a point.

I was also just thinking that some requests using the same adapter may be mocked, while others are not. It sounds like my request is too global to be practical for most others using this library.

Someone could use WebMock::StubRegistry.instance.registered_request? to check if the request is being stubbed. Even then, there isn't a true correlation between the raised exception and the request response.

🤔

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