Muzak is a mutation testing library for Elixir and Erlang applications.
Mutation testing is a way of systematically introducing bugs into your code and then running your tests to see if any of them fail. If you introduce a bug in your code
| def intermittent_failures( | |
| %{id: suite_id}, | |
| spec \\ %{10 => 100, 9 => 80, 8 => 60, 7 => 45, 6 => 32, 5 => 25, 4 => 16, 3 => 9} | |
| ) do | |
| limit = spec |> Map.values() |> Enum.max() | |
| last_100_runs = | |
| from(r in Run, | |
| where: r.suite_id == ^suite_id, | |
| order_by: [desc: r.inserted_at], |
| # My GenServer | |
| defmodule My.GenServer do | |
| def start_link() do | |
| GenServer.start_link(__MODULE__, :ok, name: __MODULE__) | |
| end | |
| def init(_) do | |
| {:ok, []} | |
| end |
| # Step 1 | |
| def create_subscription(email, plan_id, payment_method_id) do | |
| with %User{customer_id: nil, name: name} = user <- | |
| Repo.get_by(User, email: email), | |
| {:ok, %Stripe.Customer{id: customer_id}} <- | |
| Stripe.Customer.create(%{ | |
| name: name, | |
| email: email, | |
| payment_method: payment_method_id, |
| # Given that we have a `User` module, that looks something like this: | |
| defmodule User do | |
| defstruct [:name] | |
| def changeset(user, params) do | |
| # ... | |
| end | |
| end |
| defmodule Mix.Tasks.Credo.Ci do | |
| @shortdoc "Run Credo only on files that have changed since the last merge commit." | |
| @moduledoc """ | |
| Runs Credo in CI with somewhat special behavior. | |
| If the branch being tested is `master`, it runs Credo on all files. Otherwise, it only runs | |
| Credo on the files that have changed since the last merge commit, and it will fail CI if any | |
| check doesn't pass for those specific files. | |
| """ |