Bylaw.Credo.Check.Testing.NoDescribeBlocks (bylaw_credo v0.3.1)

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 higher and works with any version of Elixir.

Explanation

Avoid describe blocks in test files.

Examples

Avoid:

describe "creating a user" do
  test "returns the user" do
    assert create_user().active?
  end
end

Prefer:

test "creating a user returns an active user" do
  assert create_user().active?
end

Notes

Descriptive standalone test names make each test's behavior visible without relying on an enclosing block. When a suite grows, split it into multiple focused test files instead of grouping unrelated behavior with describe.

Path exclusions are matched against the source filename and are intended for generated files or temporary migration areas.

The check uses static AST analysis, so dynamic code generation and macro-expanded code may fall outside its signal.

Options

Configure options in .credo.exs with the check tuple:

%{
  configs: [
    %{
      name: "default",
      checks: [
        {Bylaw.Credo.Check.Testing.NoDescribeBlocks,
         [
           excluded_paths: ["test/support/"]
         ]}
      ]
    }
  ]
}
  • :excluded_paths - Paths containing any configured string are skipped. Use this for test files that are intentionally being migrated.

Usage

Add this check to Credo's checks: list in .credo.exs:

%{
  configs: [
    %{
      name: "default",
      checks: [
        {Bylaw.Credo.Check.Testing.NoDescribeBlocks, []}
      ]
    }
  ]
}

Check-Specific Parameters

Use the following parameters to configure this check:

:excluded_paths

Paths containing any configured string are skipped. Use this for test files that are intentionally being migrated.

This parameter defaults to [].

General Parameters

Like with all checks, general params can be applied.

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