Skip to content

rslota/ex_assert_eventually

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AssertEventually

CircleCI

Very simple test helper for Elixir's ExUnit framework that allows to use standard ExUnit assertions along with expressions that may fail several times until they eventually succeed.

Documentation

Documentation can be found on https://hexdocs.pm/ex_assert_eventually.

Installation

The package can be installed by adding assert_eventually to your list of dependencies in mix.exs:

def deps do
  [
    {:assert_eventually, "~> 1.0.0", only: :test}
  ]
end

AssertEventually is usually added only to the :test environment since it's used in tests. To also import AssertEventually's formatter configuration, add the :dev environment as well as :test for assert_eventually and add :assert_eventually to your .formatter.exs:

[
  import_deps: [:assert_eventually]
]

Just tell me how to use it already...

Here you go (just replace ComplexSystem with something of yours):

defmodule MyApp.SomeTest do
  use ExUnit.Case, async: true

  # Fail after 50ms of retrying with 5ms time between attempts
  use AssertEventually, timeout: 50, interval: 5

  test "get meaningful value by using normal assert" do
    {:ok, server_pid} = start_supervised(ComplexSystem)

    eventually assert {:ok, value} = ComplexSystem.get_value(server_pid)
    assert value == 42
  end

  test "get meaningful value by using assert_in_delta" do
    {:ok, server_pid} = start_supervised(ComplexSystem)

    eventually assert_in_delta 42, elem(ComplexSystem.get_value(server_pid), 1), 0
  end
end

For more details please consult the documentation.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages