Skip to content

Commit

Permalink
Add assert and refute
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmi committed Jun 30, 2016
1 parent 672ff31 commit 7076ecc
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/espec.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ defmodule ESpec do

import ESpec.Expect
use ESpec.Expect
import ESpec.Assert
import ESpec.To
import ESpec.Should
use ESpec.Should
Expand Down
15 changes: 15 additions & 0 deletions lib/espec/assert.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule ESpec.Assert do
@moduledoc """
Defines `assert` and `refute` helper functions.
"""

alias ESpec.ExpectTo
alias ESpec.Assertions.Boolean.BeTruthy
alias ESpec.Assertions.Boolean.BeFalsy

@doc "Calls be_truthy assertion"
def assert(value), do: ExpectTo.to({BeTruthy, []}, {ExpectTo, value})

@doc "Calls be_falsy assertion"
def refute(value), do: ExpectTo.to({BeFalsy, []}, {ExpectTo, value})
end
2 changes: 1 addition & 1 deletion lib/espec/assertions/boolean/be_truthy.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule ESpec.Assertions.Boolean.BeTruthy do
@moduledoc """
Defines 'be_true' assertion.
Defines 'be_truthy' assertion.
it do: expect(1).to be_truthy
"""
Expand Down
13 changes: 13 additions & 0 deletions spec/assertions/boolean/assert_and_refute_spec.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
defmodule ESpec.Assertions.Boolean.AssertAndRefuteSpec do
use ESpec, async: true

context "Success" do
it do: assert 1
it do: refute nil
end

xcontext "Errors" do
it do: assert false
it do: refute "a"
end
end
2 changes: 1 addition & 1 deletion spec/some_spec.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule SomeSpec do
use ESpec

end
33 changes: 33 additions & 0 deletions test/assertions/boolean/assert_and_refute_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
defmodule Boolean.AssertAndRefuteTest do
use ExUnit.Case, async: true

defmodule SomeSpec do
use ESpec, async: true

context "Success" do
it do: ESpec.Assert.assert 1
it do: ESpec.Assert.refute nil
end

context "Errors" do
it do: ESpec.Assert.assert false
it do: ESpec.Assert.refute "a"
end
end

setup_all do
examples = ESpec.Runner.run_examples(SomeSpec.examples)
{ :ok,
success: Enum.slice(examples, 0, 1),
errors: Enum.slice(examples, 2, 3)
}
end

test "Success", context do
Enum.each(context[:success], &(assert(&1.status == :success)))
end

test "Errors", context do
Enum.each(context[:errors], &(assert(&1.status == :failure)))
end
end
2 changes: 1 addition & 1 deletion test/assertions/boolean/be_false_test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Boolean.BeFalse do
defmodule Boolean.BeFalseTest do
use ExUnit.Case, async: true

defmodule SomeSpec do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Boolean.BeFalsy do
defmodule Boolean.BeFalsyTest do
use ExUnit.Case, async: true

defmodule SomeSpec do
Expand Down Expand Up @@ -30,4 +30,4 @@ defmodule Boolean.BeFalsy do
test "Errors", context do
Enum.each(context[:errors], &(assert(&1.status == :failure)))
end
end
end
2 changes: 1 addition & 1 deletion test/assertions/boolean/be_true_test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Boolean.BeTrue do
defmodule Boolean.BeTrueTest do
use ExUnit.Case, async: true

defmodule SomeSpec do
Expand Down
2 changes: 1 addition & 1 deletion test/assertions/boolean/be_truthy_test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Boolean.BeTruthy do
defmodule Boolean.BeTruthyTest do
use ExUnit.Case, async: true

defmodule SomeSpec do
Expand Down

0 comments on commit 7076ecc

Please sign in to comment.