# How to mock, or sneak out of it

**URL:** <https://forum.crystal-lang.org/t/how-to-mock-or-sneak-out-of-it/5573>\
**Category:** Help & Support\
**Created:** [April 15, 2023, 8:50pm UTC](https://forum.crystal-lang.org/t/how-to-mock-or-sneak-out-of-it/5573 "2023-04-15T20:50:53Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [April 15, 2023, 9:47pm UTC](https://forum.crystal-lang.org/t/how-to-mock-or-sneak-out-of-it/5573/2 "2023-04-15T21:47:36Z")

</div>

In a perfect world I think `mutli_auth` would allow you to supply a custom `HTTP::Client` instance that would be set on the underlying `OAuth2::Client` instance. This would allow you to use a mock testing implementation client that keeps tracks of the incoming requests that let you later run assertions on them, and returns pre-configured responses, e.g. a response that returns a fake token.

However, `mutli_auth` does not currently support that out of the box, nor is there a built-in testing HTTP client. The closest you can get is probably [GitHub - manastech/webmock.cr: Mock HTTP::Client](https://github.com/manastech/webmock.cr), which should allow you to mock the request/response w/o touching any internals (as it does that for you).

Related: [Redesign HTTP::Client to implement missing features · Issue #6011 · crystal-lang/crystal · GitHub](https://github.com/crystal-lang/crystal/issues/6011)

But yes, DI usually the answer when it comes to this kind of stuff, but it’s not all that common of a pattern in Ruby/Crystal it seems 😕.

Related: [[RFC] Standardized Abstractions](https://forum.crystal-lang.org/t/rfc-standardized-abstractions/4414) & [shameless plug](https://athenaframework.org/Framework/Spec/APITestCase/#Athena::Framework::Spec::APITestCase--mocking-external-dependencies).

---

_[View the full topic](https://forum.crystal-lang.org/t/how-to-mock-or-sneak-out-of-it/5573)._
