Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 17 additions & 32 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,26 @@ jobs:
strategy:
matrix:
pair:
- otp-version: '23.0'
elixir-version: '1.13.4'
- otp-version: '24.0'
elixir-version: '1.13.4'
- otp-version: '24.0'
elixir-version: '1.14.2'
- otp-version: '25.0'
elixir-version: '1.13.4'
- otp-version: '25.0'
elixir-version: '1.14.2'
- otp-version: '25.1.2'
elixir-version: '1.15.7'
- otp-version: '26.0'
elixir-version: '1.16.0'
- otp-version: '27.3.3'
elixir-version: '1.18.3'
steps:
- uses: actions/checkout@v2
- name: Set up Elixir
uses: erlef/setup-beam@988e02bfe678367a02564f65ca2e37726dc0268f
env:
ImageOS: ubuntu20
with:
otp-version: ${{matrix.pair.otp-version}}
elixir-version: ${{matrix.pair.elixir-version}}
- name: Restore dependencies cache
uses: actions/cache@v2
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-
- name: Install dependencies
run: mix deps.get
- name: Run tests
run: mix test
- name: Run tests with espec
run: mix espec
- name: Run formatters
run: mix espec spec_formatters/test_spec.exs
- name: Checkout
uses: actions/checkout@v4
- name: Set up Elixir and Erlang
uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.pair.otp-version}}
elixir-version: ${{matrix.pair.elixir-version}}
- name: Install dependencies
run: mix deps.get
- name: Run tests
run: mix test
- name: Run tests with espec
run: mix espec
- name: Run formatters
run: mix espec spec_formatters/test_spec.exs

5 changes: 4 additions & 1 deletion lib/espec/assertions/accepted.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ defmodule ESpec.Assertions.Accepted do
opts_count = Keyword.get(opts, :count) || :any
count = if opts_count == :any, do: "at least once", else: "`#{opts_count}` times"

"Expected `#{inspect(subject)}` #{to} accept `#{inspect(func)}` with `#{inspect(args)}` in process `#{inspect(pid)}` #{count}, but #{but}. The function was called with arguments #{inspect(args)}"
{
"Expected `#{inspect(subject)}` #{to} accept `#{inspect(func)}` with `#{inspect(args)}` in process `#{inspect(pid)}` #{count}, but #{but}. The function was called with arguments #{inspect(args)}",
nil
}
end
end
17 changes: 10 additions & 7 deletions lib/espec/assertions/assert_receive.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ defmodule ESpec.Assertions.AssertReceive do
end

defp error_message(_subject, [_pattern, pins, mailbox_messages], result, _positive) do
[
"Expected to receive `#{inspect(result)}` but it doesn't.",
"Pinned variables: #{inspect(pins)}",
"Process mailbox:",
messages(mailbox_messages)
]
|> Enum.join(@join_sym)
{
[
"Expected to receive `#{inspect(result)}` but it doesn't.",
"Pinned variables: #{inspect(pins)}",
"Process mailbox:",
messages(mailbox_messages)
]
|> Enum.join(@join_sym),
nil
}
end

defp messages(mailbox_messages), do: Enum.map_join(mailbox_messages, @join_sym, &inspect/1)
Expand Down
15 changes: 12 additions & 3 deletions lib/espec/assertions/be.ex
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ defmodule ESpec.Assertions.Be do
{actual_granularity, actual_delta},
positive
) do
"Expected `#{inspect(subject)} #{op} #{inspect(val)}` to be `#{positive}` but got `#{!positive}` with delta `[#{granularity}: #{delta}]`. The actual delta is [#{actual_granularity}: #{actual_delta}], with an inclusive boundary."
{
"Expected `#{inspect(subject)} #{op} #{inspect(val)}` to be `#{positive}` but got `#{!positive}` with delta `[#{granularity}: #{delta}]`. The actual delta is [#{actual_granularity}: #{actual_delta}], with an inclusive boundary.",
nil
}
end

defp error_message(
Expand All @@ -79,10 +82,16 @@ defmodule ESpec.Assertions.Be do
{actual_granularity, actual_delta},
positive
) do
"Expected `#{inspect(subject)} #{op} #{inspect(val)}` to be `#{positive}` but got `#{!positive}` with delta `{:#{granularity}, #{delta}}`. The actual delta is {:#{actual_granularity}, #{actual_delta}}, with an inclusive boundary."
{
"Expected `#{inspect(subject)} #{op} #{inspect(val)}` to be `#{positive}` but got `#{!positive}` with delta `{:#{granularity}, #{delta}}`. The actual delta is {:#{actual_granularity}, #{actual_delta}}, with an inclusive boundary.",
nil
}
end

defp error_message(subject, [op, val], _result, positive) do
"Expected `#{inspect(subject)} #{op} #{inspect(val)}` to be `#{positive}` but got `#{!positive}`."
{
"Expected `#{inspect(subject)} #{op} #{inspect(val)}` to be `#{positive}` but got `#{!positive}`.",
nil
}
end
end
5 changes: 4 additions & 1 deletion lib/espec/assertions/be_between.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ defmodule ESpec.Assertions.BeBetween do
to = if positive, do: "to", else: "not to"
but = if result, do: "it is", else: "it isn't"

"Expected `#{inspect(subject)}` #{to} be between `#{inspect(l)}` and `#{inspect(r)}`, but #{but}."
{
"Expected `#{inspect(subject)}` #{to} be between `#{inspect(l)}` and `#{inspect(r)}`, but #{but}.",
nil
}
end
end
10 changes: 8 additions & 2 deletions lib/espec/assertions/be_close_to.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,19 @@ defmodule ESpec.Assertions.BeCloseTo do
to = if positive, do: "to", else: "not to"
but = if actual_delta == delta, do: "it is", else: "it isn't"

"Expected `#{inspect(subject)}` #{to} be close to `#{inspect(value)}` with delta `#{inspect(delta)}`, but #{but}. The actual delta is {:#{granularity}, #{actual_delta}}."
{
"Expected `#{inspect(subject)}` #{to} be close to `#{inspect(value)}` with delta `#{inspect(delta)}`, but #{but}. The actual delta is {:#{granularity}, #{actual_delta}}.",
nil
}
end

defp error_message(subject, [value, delta], result, positive) do
to = if positive, do: "to", else: "not to"
but = if result, do: "it is", else: "it isn't"

"Expected `#{inspect(subject)}` #{to} be close to `#{inspect(value)}` with delta `#{inspect(delta)}`, but #{but}."
{
"Expected `#{inspect(subject)}` #{to} be close to `#{inspect(value)}` with delta `#{inspect(delta)}`, but #{but}.",
nil
}
end
end
24 changes: 20 additions & 4 deletions lib/espec/assertions/be_type.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,40 @@ defmodule ESpec.Assertions.BeType do
defp error_message(subject, :null, _result, positive) do
to = if positive, do: "to", else: "not to"
but = if positive, do: "isn't", else: "is"
"Expected `#{inspect(subject)}` #{to} be nil but it #{but}."

{
"Expected `#{inspect(subject)}` #{to} be nil but it #{but}.",
nil
}
end

defp error_message(subject, [:function, arity], _result, positive) do
to = if positive, do: "to", else: "not to"
but = if positive, do: "isn't", else: "is"
"Expected `#{inspect(subject)}` #{to} be function with arity `#{arity}` but it #{but}."

{
"Expected `#{inspect(subject)}` #{to} be function with arity `#{arity}` but it #{but}.",
nil
}
end

defp error_message(subject, [:struct, name], _result, positive) do
to = if positive, do: "to", else: "not to"
but = if positive, do: "isn't", else: "is"
"Expected `#{inspect(subject)}` #{to} be struct with name `#{name}` but it #{but}"

{
"Expected `#{inspect(subject)}` #{to} be struct with name `#{name}` but it #{but}",
nil
}
end

defp error_message(subject, type, _result, positive) do
to = if positive, do: "to", else: "not to"
but = if positive, do: "isn't", else: "is"
"Expected `#{inspect(subject)}` #{to} be `#{type}` but it #{but}."

{
"Expected `#{inspect(subject)}` #{to} be `#{type}` but it #{but}.",
nil
}
end
end
2 changes: 1 addition & 1 deletion lib/espec/assertions/binary/have_byte_size.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ defmodule ESpec.Assertions.Binary.HaveByteSize do

defp error_message(enum, val, result, positive) do
to = if positive, do: "to", else: "not to"
"Expected `#{inspect(enum)}` #{to} have `#{val}` byte(s) but it has `#{result}`."
{"Expected `#{inspect(enum)}` #{to} have `#{val}` byte(s) but it has `#{result}`.", nil}
end
end
6 changes: 5 additions & 1 deletion lib/espec/assertions/boolean/be_false.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ defmodule ESpec.Assertions.Boolean.BeFalse do
defp error_message(subject, _val, _result, positive) do
to = if positive, do: "to", else: "not to"
but = if positive, do: "it isn't", else: "it is"
"Expected `#{inspect(subject)}` #{to} be false but #{but}."

{
"Expected `#{inspect(subject)}` #{to} be false but #{but}.",
nil
}
end
end
6 changes: 5 additions & 1 deletion lib/espec/assertions/boolean/be_falsy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ defmodule ESpec.Assertions.Boolean.BeFalsy do
defp error_message(subject, _val, _result, positive) do
to = if positive, do: "to", else: "not to"
but = if positive, do: "it isn't", else: "it is"
"Expected `#{inspect(subject)}` #{to} be falsy but #{but}."

{
"Expected `#{inspect(subject)}` #{to} be falsy but #{but}.",
nil
}
end
end
6 changes: 5 additions & 1 deletion lib/espec/assertions/boolean/be_true.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ defmodule ESpec.Assertions.Boolean.BeTrue do
defp error_message(subject, _val, _result, positive) do
to = if positive, do: "to", else: "not to"
but = if positive, do: "it isn't", else: "it is"
"Expected `#{inspect(subject)}` #{to} be true but #{but}."

{
"Expected `#{inspect(subject)}` #{to} be true but #{but}.",
nil
}
end
end
6 changes: 5 additions & 1 deletion lib/espec/assertions/boolean/be_truthy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ defmodule ESpec.Assertions.Boolean.BeTruthy do
defp error_message(subject, _val, _result, positive) do
to = if positive, do: "to", else: "not to"
but = if positive, do: "it isn't", else: "it is"
"Expected `#{inspect(subject)}` #{to} be truthy but #{but}."

{
"Expected `#{inspect(subject)}` #{to} be truthy but #{but}.",
nil
}
end
end
6 changes: 5 additions & 1 deletion lib/espec/assertions/change.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ defmodule ESpec.Assertions.Change do
defp error_message(subject, [func], _result, positive) do
to = if positive, do: "to", else: "not to"
but = if positive, do: "didn't change", else: "changed"
"Expected `#{inspect(subject)}` #{to} change the value of `#{inspect(func)}`, but it #{but}."

{
"Expected `#{inspect(subject)}` #{to} change the value of `#{inspect(func)}`, but it #{but}.",
nil
}
end
end
10 changes: 8 additions & 2 deletions lib/espec/assertions/change_by.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ defmodule ESpec.Assertions.ChangeBy do
defp error_message(subject, [func, value], {_then, _initial, true}, positive) do
to = if positive, do: "to", else: "not to"

"Expected `#{inspect(subject)}` #{to} change the value of `#{inspect(func)}` by `#{inspect(Keyword.get(value, :by))}`, but was not changed"
{
"Expected `#{inspect(subject)}` #{to} change the value of `#{inspect(func)}` by `#{inspect(Keyword.get(value, :by))}`, but was not changed",
nil
}
end

defp error_message(subject, [func, value], {then, initial, false}, positive) do
to = if positive, do: "to", else: "not to"

"Expected `#{inspect(subject)}` #{to} change the value of `#{inspect(func)}` by `#{inspect(Keyword.get(value, :by))}`, but was changed by `#{inspect(then - initial)}`"
{
"Expected `#{inspect(subject)}` #{to} change the value of `#{inspect(func)}` by `#{inspect(Keyword.get(value, :by))}`, but was changed by `#{inspect(then - initial)}`",
nil
}
end
end
10 changes: 8 additions & 2 deletions lib/espec/assertions/change_from_to.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ defmodule ESpec.Assertions.ChangeFromTo do
defp error_message(subject, [func, before, value], {then, _initial, true, false}, positive) do
to = if positive, do: "to", else: "not to"

"Expected `#{inspect(subject)}` #{to} change the value of `#{inspect(func)}` from `#{inspect(before)}` to `#{inspect(value)}`, but the value is `#{then}`."
{
"Expected `#{inspect(subject)}` #{to} change the value of `#{inspect(func)}` from `#{inspect(before)}` to `#{inspect(value)}`, but the value is `#{then}`.",
nil
}
end

defp error_message(subject, [func, before, value], {_then, initial, false, _}, positive) do
to = if positive, do: "to", else: "not to"

"Expected `#{inspect(subject)}` #{to} change the value of `#{inspect(func)}` from `#{inspect(before)}` to `#{inspect(value)}`, but the initial value is `#{initial}`."
{
"Expected `#{inspect(subject)}` #{to} change the value of `#{inspect(func)}` from `#{inspect(before)}` to `#{inspect(value)}`, but the initial value is `#{initial}`.",
nil
}
end
end
15 changes: 12 additions & 3 deletions lib/espec/assertions/change_to.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,27 @@ defmodule ESpec.Assertions.ChangeTo do
defp error_message(subject, [func, value], {then, true, false, false}, positive) do
to = if positive, do: "to", else: "not to"

"Expected `#{inspect(subject)}` #{to} change the value of `#{inspect(func)}` to `#{inspect(value)}`, but was changed to `#{inspect(then)}`"
{
"Expected `#{inspect(subject)}` #{to} change the value of `#{inspect(func)}` to `#{inspect(value)}`, but was changed to `#{inspect(then)}`",
nil
}
end

defp error_message(subject, [func, value], {_then, true, false, true}, positive) do
to = if positive, do: "to", else: "not to"

"Expected `#{inspect(subject)}` #{to} change the value of `#{inspect(func)}` to `#{inspect(value)}`, but was not changed"
{
"Expected `#{inspect(subject)}` #{to} change the value of `#{inspect(func)}` to `#{inspect(value)}`, but was not changed",
nil
}
end

defp error_message(subject, [func, value], {_then, false, _, _}, positive) do
to = if positive, do: "to", else: "not to"

"Expected `#{inspect(subject)}` #{to} change the value of `#{inspect(func)}` to `#{inspect(value)}`, but the initial value is `#{inspect(value)}`"
{
"Expected `#{inspect(subject)}` #{to} change the value of `#{inspect(func)}` to `#{inspect(value)}`, but the initial value is `#{inspect(value)}`",
nil
}
end
end
2 changes: 1 addition & 1 deletion lib/espec/assertions/contain_exactly.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ defmodule ESpec.Assertions.ContainExactly do
if positive do
{m, %{diff_fn: fn -> diff(subject, data) end}}
else
m
{m, nil}
end
end
end
4 changes: 2 additions & 2 deletions lib/espec/assertions/enum/be_empty.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ defmodule ESpec.Assertions.Enum.BeEmpty do

defp error_message(enum, _data, result, positive) do
if positive do
"Expected `#{inspect(enum)}` to be empty, but it has `#{result}` elements."
{"Expected `#{inspect(enum)}` to be empty, but it has `#{result}` elements.", nil}
else
"Expected `#{inspect(enum)}` not to be empty, but it is."
{"Expected `#{inspect(enum)}` not to be empty, but it is.", nil}
end
end
end
3 changes: 2 additions & 1 deletion lib/espec/assertions/enum/have_all.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ defmodule ESpec.Assertions.Enum.HaveAll do
to = if positive, do: "to", else: "not to"
returns = if positive, do: "`false` for some", else: "`true` for all"

"Expected `#{inspect(func)}` #{to} return `true` for all elements in `#{inspect(enum)}`, but it returns #{returns}."
{"Expected `#{inspect(func)}` #{to} return `true` for all elements in `#{inspect(enum)}`, but it returns #{returns}.",
nil}
end
end
3 changes: 2 additions & 1 deletion lib/espec/assertions/enum/have_any.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ defmodule ESpec.Assertions.Enum.HaveAny do
defp error_message(enum, func, result, positive) do
to = if positive, do: "to", else: "not to"

"Expected `#{inspect(func)}` #{to} return `true` for at least one element in `#{inspect(enum)}` but it returns `#{result}` for all."
{"Expected `#{inspect(func)}` #{to} return `true` for at least one element in `#{inspect(enum)}` but it returns `#{result}` for all.",
nil}
end
end
3 changes: 2 additions & 1 deletion lib/espec/assertions/enum/have_count_by.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ defmodule ESpec.Assertions.Enum.HaveCountBy do
defp error_message(enum, [func, val], result, positive) do
to = if positive, do: "to", else: "not to"

"Expected `#{inspect(enum)}` #{to} have count_by `#{inspect(func)}` be equal to `#{val}` but it has `#{result}` elements."
{"Expected `#{inspect(enum)}` #{to} have count_by `#{inspect(func)}` be equal to `#{val}` but it has `#{result}` elements.",
nil}
end
end
Loading
Loading