Need help with power_assert_ex?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

ma2gedev
206 Stars 6 Forks Other 170 Commits 1 Opened issues

Description

Power Assert in Elixir. Shows evaluation results each expression.

Services available

!
?

Need anything else?

Contributors list

# 108,523
Elixir
Erlang
Shell
PHP
135 commits
# 135,681
C
jetson-...
webrtc
Ubuntu
4 commits
# 181,349
Erlang
Emacs
emacs-l...
cowboy
1 commit
# 133,043
Elixir
elixir-...
dalvik
sidekiq
1 commit
# 51,025
elixir-...
Erlang
yarn
webperf...
1 commit

Power Assert

hex.pm version hex.pm daily downloads hex.pm weekly downloads hex.pm downloads Build Status License

Power Assert makes test results easier to understand, without changing your ExUnit test code.

Demo

Example test is here:

test "Enum.at should return the element at the given index" do
  array = [1, 2, 3, 4, 5, 6]; index = 2; two = 2
  assert array |> Enum.at(index) == two
end

Here is the difference between ExUnit and Power Assert results:

Difference between ExUnit and Power Assert

Enjoy :muscle: !

Installation

Add Power Assert to your

mix.exs
dependencies:
defp deps do
  [{:power_assert, "~> 0.2.0", only: :test}]
end

and fetch

$ mix deps.get
.

Usage

Replace

use ExUnit.Case
into
use PowerAssert
in your test code:
## before(ExUnit)
defmodule YourAwesomeTest do
  use ExUnit.Case  # 

Done! You can run

$ mix test
.

Use with ExUnit.CaseTemplate

Insert

use PowerAssert
with
ExUnit.CaseTemplate.using/2
macro:
## before(ExUnit.CaseTemplate)
defmodule YourAwesomeTest do
  use ExUnit.CaseTemplate
end

after(PowerAssert)

defmodule YourAwesomeTest do use ExUnit.CaseTemplate

add the following

using do quote do use PowerAssert end end end

protip: useful command to replace
use ExUnit.Case

$ git grep -l 'use ExUnit\.Case' | xargs sed -i.bak -e 's/use ExUnit\.Case/use PowerAssert/g'

How to use with other framework depending on ExUnit such as ExSpec

ExSpec

Append

use PowerAssert
after
use ExSpec
:
defmodule ExSpecBasedTest do
  use ExSpec
  use PowerAssert   # 

See also: test/exspec/exspec_test.exs

API

Only provide

assert
macro:
assert(expression, message \\ nil)

Dependencies

  • ExUnit

Limitation

  • NOT SUPPORTED
    • match expression ex:
      assert List.first(x = [false])
    • fn expression ex:
      assert fn(x) -> x == 1 end.(2)
    • :: expression ex:
      << x :: bitstring >>
    • this means string interpolations also unsupported ex:
      "#{x} hoge"
    • sigil expression ex:
      ~w(hoge fuga)
    • quote arguments ex:
      assert quote(@opts, do: :hoge)
    • case expression
    • getandupdatein/2, putin/2, update_in/2, for/1
    • <<>> expression includes attributes
      <>; <>
    • __MODULE__.Foo
    • many macros maybe caught error...

Resources

Author

Takayuki Matsubara (@ma2ge on twitter)

License

Distributed under the Apache 2 License.

Check LICENSE files for more information.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.