OptimumCredo.Check.Warning.HttpClientInTest (OptimumCredo v0.5.0)

View Source

Basics

This check is disabled by default.

Learn how to enable it via .credo.exs.

This check has a base priority of low and works with any version of Elixir.

Explanation

Tests must not hit the network. Stub external services with Mox, Bypass, Req.Test or fixtures.

Bad: HTTPoison.get!("https://example.com/api") Good: Mox.expect(HttpMock, :get, fn _ -> {:ok, response} end)

Check-Specific Parameters

Use the following parameters to configure this check:

:client_modules

HTTP client modules (atoms or strings) whose remote calls are reported.

This parameter defaults to [HTTPoison, HTTPotion, Req, Tesla, Finch, Mojito, Mint.HTTP, :httpc, :hackney].

:mock_wrappers

Call names whose arguments are treated as mock definitions and skipped.

This parameter defaults to [:expect, :expect_once, :stub, :stub_with, :mock, :mock_global, :with_mock, :with_mocks].

:non_request_functions

Client functions that build or configure but never send a request.

This parameter defaults to [:new, :build, :client, :build_client, :start, :start_link, :child_spec, :merge, :update, :attach, :put_header, :put_headers, :put_option, :put_private].

:allow_local_urls

Accept calls whose literal URL points at localhost or a loopback address.

This parameter defaults to true.

General Parameters

Like with all checks, general params can be applied.

Parameters can be configured via the .credo.exs config file.