Bex

The set of mix tasks to help dealing with behaviours and mocks

Objective

The goal of this library is to make planting better testing into a source code as smoothly and fluently as possible. It’s barely needed for experienced developers, but I always find myself struggling to recall all the places in the source code I have to amend to convert a bare call into a behaviour-baked implementation.

The main task Mix.Tasks.Bex.Generate would do the following things:

Use-case

Consider the necessity to test the function that calls Process.send_after/4 function in your code. Assuming we trust that Process.send_after/4 itself works, we’d like to mock it and validate the proper call with proper arguments happened.

For that we might run Mix.Tasks.Bex.Generate task, review generated files, and voilà. The next mix test, or mix test test/bex would execute the tests for the newly created behaviour using Mox.

Usage

mix bex.generate --function Process.send_after/4

The above will generate the behaviour module Bex.Behaviours.Process and its default implementation which should be called instead of a direct call to the original function.

Also Mox scaffold and telemetry call will be generated.

Installation

def deps do
  [
    {:bex, "~> 0.2"}
  ]
end

Documentation