• Stars
    star
    212
  • Rank 179,346 (Top 4 %)
  • Language
    Elixir
  • License
    Other
  • Created over 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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 πŸ’ͺ !

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.

More Repositories

1

bundle-star

Star github repositories automatically when you bundle installing
Ruby
53
star
2

breadcrumble

A breadcrumbs plugin for Ruby on Rails.
Ruby
39
star
3

chrono_logger

A lock-free logger with timebased file rotation.
Ruby
30
star
4

breadcrumble_ex

Elixir lang port of Breadcrumble
Elixir
25
star
5

faraday-encoding

A Faraday Middleware sets body encoding when specified by server.
Ruby
25
star
6

luhn_ex

Luhn algorithm in Elixir
Elixir
16
star
7

mix-star

Elixir Mix task to starring GitHub repository with `mix deps.get`ting dependent library
Elixir
12
star
8

ltsvex

LTSV parser implementation in Elixir
Elixir
10
star
9

qiita_ex

Qiita API v2 Interface for Elixir
Elixir
7
star
10

gimei_ex

Elixir
7
star
11

isucon4-qual-phoenix

Elixir
6
star
12

octoparts-rb

Ruby client for the Octoparts API
Ruby
6
star
13

netrcex

Reads netrc files implemented in Elixir
Elixir
4
star
14

a4nt

A4nt is a simple announcements plugin for Ruby on Rails.
Ruby
2
star
15

canonical_url-rails

URL canonicalization for Rails.
Ruby
2
star
16

gem-star

Star github repository automatically when you gem install.
Ruby
2
star
17

qiita-ex

Qiita API sample code
Elixir
2
star
18

yesod-sample

yesod sample application
Haskell
2
star
19

syncdeckjs

synchronize slide with deck.js
JavaScript
2
star
20

breadcrumble_demo

breadcrumble demo application
Ruby
2
star
21

ma2gedev.github.com

my page
JavaScript
1
star
22

instagram-ruby-gem

The official gem for the Instagram API
Ruby
1
star
23

power_assert_sample

Power Assert sample test code in Elixir
Elixir
1
star
24

ruby-behaviour-checker

Check ruby code behaviour with browser.
Ruby
1
star
25

t5

template to face technical debt
Ruby
1
star
26

rails4beta_on_heroku

rails 4.0 beta run on heroku
Ruby
1
star
27

doctestex

doctest sample code on Elixir
Elixir
1
star
28

graphql_sample

GraphQL Sample application for Elixir
Elixir
1
star
29

pebbles-orz

A joke gem to define aliases
Ruby
1
star
30

fakeb

social bookmark application like hatena bookmark
Ruby
1
star
31

graphql-samples

GraphQL implementation samples
Elixir
1
star
32

md2deckjs

convert markdown file to deck.js slide
1
star
33

tecotbot

@tecotbot code. https://twitter.com/#!/tecotbot
Ruby
1
star
34

jsp2erb

convert jsp into erb
Ruby
1
star
35

groovy_meta

test groovy metaprogramming
Groovy
1
star
36

advent-of-code

My solutions for Advent of Code
Rust
1
star