ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - ma2gedev/power_assert_ex: Power Assert in Elixir. Shows evaluation results each expression.
Power Assert in Elixir. Shows evaluation results each expression. - ma2gedev/power_assert_ex
Visit Site

GitHub - ma2gedev/power_assert_ex: Power Assert in Elixir. Shows evaluation results each expression.

GitHub - ma2gedev/power_assert_ex: Power Assert in Elixir. Shows evaluation results each expression.

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  # <-- **HERE**
end

## after(PowerAssert)
defmodule YourAwesomeTest do
  use PowerAssert  # <-- **REPLACED**
end

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   # <-- append

  describe "describe" do
    it "it" do
      assert something == "hoge"
    end
  end
end

See also: test/ex_spec/ex_spec_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
    • get_and_update_in/2, put_in/2, update_in/2, for/1
    • <<>> expression includes attributes <<@x, "y">>; <<x :: binary, "y">>
    • __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.

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory