Rbtz.CredoChecks.Warning.ReqTestWithoutVerifyOnExit (rbtz_credo_checks v0.2.0)

Copy Markdown View Source

Basics

This check is disabled by default.

Learn how to enable it via .credo.exs.

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

Explanation

Requires test modules that mock HTTP with Req.Test.stub/2 or Req.Test.expect/3 to call Req.Test.verify_on_exit!/0 in a setup/setup_all block.

Without verify_on_exit!, an expect/3 whose stub is never invoked will silently pass the test instead of raising at the end — masking code paths that skipped the HTTP call entirely. Calling it once in setup wires up the on-exit hook for every test in the module.

The check runs only on test files (test/**/*_test.exs). If the module calls Req.Test.stub or Req.Test.expect anywhere, there must be a Req.Test.verify_on_exit!() (or bare verify_on_exit!()) inside a setup / setup_all block. A top-level call outside of setup does not count — it must run per test.

Bad

defmodule MyTest do
  use MyApp.DataCase, async: true

  test "fetches data" do
    Req.Test.expect(MyApp.HTTP, fn conn -> ... end)
    # ...
  end
end

Good

defmodule MyTest do
  use MyApp.DataCase, async: true

  setup :verify_on_exit!

  test "fetches data" do
    Req.Test.expect(MyApp.HTTP, fn conn -> ... end)
    # ...
  end
end

Check-Specific Parameters

There are no specific parameters for this check.

General Parameters

Like with all checks, general params can be applied.

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