diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml index 57c6f5bf..3efca605 100644 --- a/.github/workflows/elixir.yml +++ b/.github/workflows/elixir.yml @@ -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 diff --git a/lib/espec/assertions/accepted.ex b/lib/espec/assertions/accepted.ex index 4ced8312..c377fd8f 100644 --- a/lib/espec/assertions/accepted.ex +++ b/lib/espec/assertions/accepted.ex @@ -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 diff --git a/lib/espec/assertions/assert_receive.ex b/lib/espec/assertions/assert_receive.ex index 6279bb85..923b3b93 100644 --- a/lib/espec/assertions/assert_receive.ex +++ b/lib/espec/assertions/assert_receive.ex @@ -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) diff --git a/lib/espec/assertions/be.ex b/lib/espec/assertions/be.ex index dd39b9ce..99a2d925 100644 --- a/lib/espec/assertions/be.ex +++ b/lib/espec/assertions/be.ex @@ -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( @@ -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 diff --git a/lib/espec/assertions/be_between.ex b/lib/espec/assertions/be_between.ex index dd90a1e5..bf7b720c 100644 --- a/lib/espec/assertions/be_between.ex +++ b/lib/espec/assertions/be_between.ex @@ -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 diff --git a/lib/espec/assertions/be_close_to.ex b/lib/espec/assertions/be_close_to.ex index db2c894d..0e76563b 100644 --- a/lib/espec/assertions/be_close_to.ex +++ b/lib/espec/assertions/be_close_to.ex @@ -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 diff --git a/lib/espec/assertions/be_type.ex b/lib/espec/assertions/be_type.ex index 7df2746f..045456c8 100644 --- a/lib/espec/assertions/be_type.ex +++ b/lib/espec/assertions/be_type.ex @@ -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 diff --git a/lib/espec/assertions/binary/have_byte_size.ex b/lib/espec/assertions/binary/have_byte_size.ex index 7bde1352..3e34e534 100644 --- a/lib/espec/assertions/binary/have_byte_size.ex +++ b/lib/espec/assertions/binary/have_byte_size.ex @@ -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 diff --git a/lib/espec/assertions/boolean/be_false.ex b/lib/espec/assertions/boolean/be_false.ex index e07b43d7..9f4099f4 100644 --- a/lib/espec/assertions/boolean/be_false.ex +++ b/lib/espec/assertions/boolean/be_false.ex @@ -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 diff --git a/lib/espec/assertions/boolean/be_falsy.ex b/lib/espec/assertions/boolean/be_falsy.ex index f2016769..c26f2550 100644 --- a/lib/espec/assertions/boolean/be_falsy.ex +++ b/lib/espec/assertions/boolean/be_falsy.ex @@ -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 diff --git a/lib/espec/assertions/boolean/be_true.ex b/lib/espec/assertions/boolean/be_true.ex index 861a4aea..b2599230 100644 --- a/lib/espec/assertions/boolean/be_true.ex +++ b/lib/espec/assertions/boolean/be_true.ex @@ -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 diff --git a/lib/espec/assertions/boolean/be_truthy.ex b/lib/espec/assertions/boolean/be_truthy.ex index eecbbc2f..76a7af87 100644 --- a/lib/espec/assertions/boolean/be_truthy.ex +++ b/lib/espec/assertions/boolean/be_truthy.ex @@ -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 diff --git a/lib/espec/assertions/change.ex b/lib/espec/assertions/change.ex index 058bd0f4..a3958244 100644 --- a/lib/espec/assertions/change.ex +++ b/lib/espec/assertions/change.ex @@ -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 diff --git a/lib/espec/assertions/change_by.ex b/lib/espec/assertions/change_by.ex index 3558c70e..a6a9ea7b 100644 --- a/lib/espec/assertions/change_by.ex +++ b/lib/espec/assertions/change_by.ex @@ -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 diff --git a/lib/espec/assertions/change_from_to.ex b/lib/espec/assertions/change_from_to.ex index 06b502e7..9cc268f1 100644 --- a/lib/espec/assertions/change_from_to.ex +++ b/lib/espec/assertions/change_from_to.ex @@ -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 diff --git a/lib/espec/assertions/change_to.ex b/lib/espec/assertions/change_to.ex index 4cd870a0..97736d55 100644 --- a/lib/espec/assertions/change_to.ex +++ b/lib/espec/assertions/change_to.ex @@ -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 diff --git a/lib/espec/assertions/contain_exactly.ex b/lib/espec/assertions/contain_exactly.ex index c223fbb6..1053ad3c 100644 --- a/lib/espec/assertions/contain_exactly.ex +++ b/lib/espec/assertions/contain_exactly.ex @@ -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 diff --git a/lib/espec/assertions/enum/be_empty.ex b/lib/espec/assertions/enum/be_empty.ex index 7d729419..b74d9cc4 100644 --- a/lib/espec/assertions/enum/be_empty.ex +++ b/lib/espec/assertions/enum/be_empty.ex @@ -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 diff --git a/lib/espec/assertions/enum/have_all.ex b/lib/espec/assertions/enum/have_all.ex index c4a0f76e..e634c907 100644 --- a/lib/espec/assertions/enum/have_all.ex +++ b/lib/espec/assertions/enum/have_all.ex @@ -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 diff --git a/lib/espec/assertions/enum/have_any.ex b/lib/espec/assertions/enum/have_any.ex index 909775f7..72aaa571 100644 --- a/lib/espec/assertions/enum/have_any.ex +++ b/lib/espec/assertions/enum/have_any.ex @@ -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 diff --git a/lib/espec/assertions/enum/have_count_by.ex b/lib/espec/assertions/enum/have_count_by.ex index def71416..e43afeb9 100644 --- a/lib/espec/assertions/enum/have_count_by.ex +++ b/lib/espec/assertions/enum/have_count_by.ex @@ -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 diff --git a/lib/espec/assertions/enum/have_max.ex b/lib/espec/assertions/enum/have_max.ex index 87589034..784edc70 100644 --- a/lib/espec/assertions/enum/have_max.ex +++ b/lib/espec/assertions/enum/have_max.ex @@ -19,6 +19,7 @@ defmodule ESpec.Assertions.Enum.HaveMax do defp error_message(enum, val, result, positive) do to = if positive, do: "to be", else: "not to be" - "Expected the maximum value of `#{inspect(enum)}` #{to} `#{val}` but the maximum is `#{result}`." + {"Expected the maximum value of `#{inspect(enum)}` #{to} `#{val}` but the maximum is `#{result}`.", + nil} end end diff --git a/lib/espec/assertions/enum/have_max_by.ex b/lib/espec/assertions/enum/have_max_by.ex index 56a602b4..103638a4 100644 --- a/lib/espec/assertions/enum/have_max_by.ex +++ b/lib/espec/assertions/enum/have_max_by.ex @@ -19,6 +19,7 @@ defmodule ESpec.Assertions.Enum.HaveMaxBy do defp error_message(enum, [func, val], result, positive) do to = if positive, do: "to be", else: "not to be" - "Expected the maximum value of `#{inspect(enum)}` using `#{inspect(func)}` #{to} `#{val}` but the maximum is `#{result}`." + {"Expected the maximum value of `#{inspect(enum)}` using `#{inspect(func)}` #{to} `#{val}` but the maximum is `#{result}`.", + nil} end end diff --git a/lib/espec/assertions/enum/have_min.ex b/lib/espec/assertions/enum/have_min.ex index 5a0caf7b..7e131315 100644 --- a/lib/espec/assertions/enum/have_min.ex +++ b/lib/espec/assertions/enum/have_min.ex @@ -19,6 +19,7 @@ defmodule ESpec.Assertions.Enum.HaveMin do defp error_message(enum, val, result, positive) do to = if positive, do: "to be", else: "not to be" - "Expected the minimum value of `#{inspect(enum)}` #{to} `#{val}` but the minimum is `#{result}`." + {"Expected the minimum value of `#{inspect(enum)}` #{to} `#{val}` but the minimum is `#{result}`.", + nil} end end diff --git a/lib/espec/assertions/enum/have_min_by.ex b/lib/espec/assertions/enum/have_min_by.ex index 3c19e095..4fae2cc5 100644 --- a/lib/espec/assertions/enum/have_min_by.ex +++ b/lib/espec/assertions/enum/have_min_by.ex @@ -19,6 +19,7 @@ defmodule ESpec.Assertions.Enum.HaveMinBy do defp error_message(enum, [func, val], result, positive) do to = if positive, do: "to be", else: "not to be" - "Expected the minimum value of `#{inspect(enum)}` using `#{inspect(func)}` #{to} `#{val}` but the minimum is `#{result}`." + {"Expected the minimum value of `#{inspect(enum)}` using `#{inspect(func)}` #{to} `#{val}` but the minimum is `#{result}`.", + nil} end end diff --git a/lib/espec/assertions/enum_string/have.ex b/lib/espec/assertions/enum_string/have.ex index 543b8e94..fe389607 100644 --- a/lib/espec/assertions/enum_string/have.ex +++ b/lib/espec/assertions/enum_string/have.ex @@ -63,12 +63,13 @@ defmodule ESpec.Assertions.EnumString.Have do {m, %{diff_fn: fn -> ESpec.Diff.diff(actual, value) end}} else - m + {m, nil} end end defp build_error_message(enum, value, result, positive) do - "Expected `#{inspect(enum)}` #{to(positive)} have `#{inspect(value)}`, but it #{has(result)}." + {"Expected `#{inspect(enum)}` #{to(positive)} have `#{inspect(value)}`, but it #{has(result)}.", + nil} end defp get_value(list, key) when is_list(list) do diff --git a/lib/espec/assertions/enum_string/have_at.ex b/lib/espec/assertions/enum_string/have_at.ex index cc547ec7..2dd6ef0b 100644 --- a/lib/espec/assertions/enum_string/have_at.ex +++ b/lib/espec/assertions/enum_string/have_at.ex @@ -32,7 +32,7 @@ defmodule ESpec.Assertions.EnumString.HaveAt do if positive and not is_binary(enum) do {m, %{diff_fn: fn -> ESpec.Diff.diff(Enum.at(enum, pos), val) end}} else - m + {m, nil} end end end diff --git a/lib/espec/assertions/enum_string/have_count.ex b/lib/espec/assertions/enum_string/have_count.ex index 3143ce03..b1f04b59 100644 --- a/lib/espec/assertions/enum_string/have_count.ex +++ b/lib/espec/assertions/enum_string/have_count.ex @@ -25,6 +25,6 @@ defmodule ESpec.Assertions.EnumString.HaveCount do defp error_message(enum, val, result, positive) do to = if positive, do: "to", else: "not to" - "Expected `#{inspect(enum)}` #{to} have `#{val}` elements but it has `#{result}`." + {"Expected `#{inspect(enum)}` #{to} have `#{val}` elements but it has `#{result}`.", nil} end end diff --git a/lib/espec/assertions/eq.ex b/lib/espec/assertions/eq.ex index a3537a44..501da08a 100644 --- a/lib/espec/assertions/eq.ex +++ b/lib/espec/assertions/eq.ex @@ -24,7 +24,7 @@ defmodule ESpec.Assertions.Eq do if positive do {m, %{diff_fn: fn -> ESpec.Diff.diff(subject, data) end}} else - m + {m, nil} end end end diff --git a/lib/espec/assertions/eql.ex b/lib/espec/assertions/eql.ex index 9d6584d9..c3095f2b 100644 --- a/lib/espec/assertions/eql.ex +++ b/lib/espec/assertions/eql.ex @@ -24,7 +24,7 @@ defmodule ESpec.Assertions.Eql do if positive do {m, %{diff_fn: fn -> ESpec.Diff.diff(subject, data) end}} else - m + {m, nil} end end end diff --git a/lib/espec/assertions/interface.ex b/lib/espec/assertions/interface.ex index f704d41e..090d019d 100644 --- a/lib/espec/assertions/interface.ex +++ b/lib/espec/assertions/interface.ex @@ -34,13 +34,7 @@ defmodule ESpec.Assertions.Interface do end defp raise_error(subject, data, result, positive, stacktrace \\ nil) do - e = error_message(subject, data, result, positive) - - {message, extra} = - case e do - {_, _} -> e - _ -> {e, nil} - end + {message, extra} = error_message(subject, data, result, positive) raise ESpec.AssertionError, subject: subject, diff --git a/lib/espec/assertions/list/have_hd.ex b/lib/espec/assertions/list/have_hd.ex index 706c85d5..da9cc2ed 100644 --- a/lib/espec/assertions/list/have_hd.ex +++ b/lib/espec/assertions/list/have_hd.ex @@ -23,7 +23,7 @@ defmodule ESpec.Assertions.List.HaveHd do if positive and not is_binary(list) do {m, %{diff_fn: fn -> ESpec.Diff.diff(hd(list), val) end}} else - m + {m, nil} end end end diff --git a/lib/espec/assertions/list/have_tl.ex b/lib/espec/assertions/list/have_tl.ex index 8b32db3a..9ad17691 100644 --- a/lib/espec/assertions/list/have_tl.ex +++ b/lib/espec/assertions/list/have_tl.ex @@ -25,7 +25,7 @@ defmodule ESpec.Assertions.List.HaveTl do if positive and not is_binary(list) do {m, %{diff_fn: fn -> ESpec.Diff.diff(tl(list), val) end}} else - m + {m, nil} end end end diff --git a/lib/espec/assertions/list_string/have_first.ex b/lib/espec/assertions/list_string/have_first.ex index f6ffd2e6..cc2be472 100644 --- a/lib/espec/assertions/list_string/have_first.ex +++ b/lib/espec/assertions/list_string/have_first.ex @@ -32,7 +32,7 @@ defmodule ESpec.Assertions.ListString.HaveFirst do if positive and not is_binary(list) do {m, %{diff_fn: fn -> ESpec.Diff.diff(List.first(list), val) end}} else - m + {m, nil} end end end diff --git a/lib/espec/assertions/list_string/have_last.ex b/lib/espec/assertions/list_string/have_last.ex index 0a1186b1..c20418df 100644 --- a/lib/espec/assertions/list_string/have_last.ex +++ b/lib/espec/assertions/list_string/have_last.ex @@ -32,7 +32,7 @@ defmodule ESpec.Assertions.ListString.HaveLast do if positive and not is_binary(list) do {m, %{diff_fn: fn -> ESpec.Diff.diff(List.last(list), val) end}} else - m + {m, nil} end end end diff --git a/lib/espec/assertions/map/have_key.ex b/lib/espec/assertions/map/have_key.ex index 3b11551e..c7f1319c 100644 --- a/lib/espec/assertions/map/have_key.ex +++ b/lib/espec/assertions/map/have_key.ex @@ -19,6 +19,10 @@ defmodule ESpec.Assertions.Map.HaveKey do defp error_message(dict, val, _result, positive) do to = if positive, do: "to", else: "not to" but = if positive, do: "doesn't have", else: "has" - "Expected `#{inspect(dict)}` #{to} have key `#{inspect(val)}` but it #{but}." + + { + "Expected `#{inspect(dict)}` #{to} have key `#{inspect(val)}` but it #{but}.", + nil + } end end diff --git a/lib/espec/assertions/map/have_value.ex b/lib/espec/assertions/map/have_value.ex index d89a5a7c..e8027e7c 100644 --- a/lib/espec/assertions/map/have_value.ex +++ b/lib/espec/assertions/map/have_value.ex @@ -19,6 +19,10 @@ defmodule ESpec.Assertions.Map.HaveValue do defp error_message(dict, val, _result, positive) do to = if positive, do: "to", else: "not to" but = if positive, do: "doesn't have", else: "has" - "Expected `#{inspect(dict)}` #{to} have value `#{inspect(val)}` but it #{but}." + + { + "Expected `#{inspect(dict)}` #{to} have value `#{inspect(val)}` but it #{but}.", + nil + } end end diff --git a/lib/espec/assertions/match.ex b/lib/espec/assertions/match.ex index 8609b580..b67da91b 100644 --- a/lib/espec/assertions/match.ex +++ b/lib/espec/assertions/match.ex @@ -19,6 +19,10 @@ defmodule ESpec.Assertions.Match do defp error_message(subject, data, _result, positive) do to = if positive, do: "to", else: "not to" but = if positive, do: "doesn't", else: "does" - "Expected `#{inspect(subject)}` #{to} match (=~) `#{inspect(data)}`, but it #{but}." + + { + "Expected `#{inspect(subject)}` #{to} match (=~) `#{inspect(data)}`, but it #{but}.", + nil + } end end diff --git a/lib/espec/assertions/match_pattern.ex b/lib/espec/assertions/match_pattern.ex index ce030501..5a781487 100644 --- a/lib/espec/assertions/match_pattern.ex +++ b/lib/espec/assertions/match_pattern.ex @@ -25,6 +25,10 @@ defmodule ESpec.Assertions.MatchPattern do data = Macro.to_string(pattern) to = if positive, do: "to", else: "not to" but = if positive, do: "doesn't", else: "does" - "Expected `#{inspect(subject)}` #{to} match pattern (=) `#{data}`, but it #{but}." + + { + "Expected `#{inspect(subject)}` #{to} match pattern (=) `#{data}`, but it #{but}.", + nil + } end end diff --git a/lib/espec/assertions/pid/be_alive.ex b/lib/espec/assertions/pid/be_alive.ex index 0a20522a..3cb40dc2 100644 --- a/lib/espec/assertions/pid/be_alive.ex +++ b/lib/espec/assertions/pid/be_alive.ex @@ -19,6 +19,6 @@ defmodule ESpec.Assertions.PID.BeAlive 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 alive but #{but}." + {"Expected `#{inspect(subject)}` #{to} be alive but #{but}.", nil} end end diff --git a/lib/espec/assertions/raise_exception.ex b/lib/espec/assertions/raise_exception.ex index c1e7280b..e713f517 100644 --- a/lib/espec/assertions/raise_exception.ex +++ b/lib/espec/assertions/raise_exception.ex @@ -64,9 +64,15 @@ defmodule ESpec.Assertions.RaiseException do defp error_message(subject, [], false, positive) do if positive do - "Expected #{inspect(subject)} to raise an exception, but nothing was raised." + { + "Expected #{inspect(subject)} to raise an exception, but nothing was raised.", + nil + } else - "Expected #{inspect(subject)} not to raise an exception, but an exception was raised." + { + "Expected #{inspect(subject)} not to raise an exception, but an exception was raised.", + nil + } end end @@ -74,25 +80,40 @@ defmodule ESpec.Assertions.RaiseException do if positive do case err_module do {false, nil} -> - "Expected #{inspect(subject)} to raise the `#{module}` exception, but nothing was raised." + { + "Expected #{inspect(subject)} to raise the `#{module}` exception, but nothing was raised.", + nil + } err_module -> - "Expected #{inspect(subject)} to raise the `#{module}` exception, but `#{err_module}` was raised instead." + { + "Expected #{inspect(subject)} to raise the `#{module}` exception, but `#{err_module}` was raised instead.", + nil + } end else - "Expected #{inspect(subject)} not to raise the `#{module}` exception, but the `#{err_module}` exception was raised." + { + "Expected #{inspect(subject)} not to raise the `#{module}` exception, but the `#{err_module}` exception was raised.", + nil + } end end defp error_message(subject, [module, message], false, positive) do to = if positive, do: "to", else: "not to" - "Expected #{inspect(subject)} #{to} raise the `#{module}` exception with the message `#{message}`, but nothing was raised." + { + "Expected #{inspect(subject)} #{to} raise the `#{module}` exception with the message `#{message}`, but nothing was raised.", + nil + } end defp error_message(subject, [module, message], [err_module, err_message], positive) do to = if positive, do: "to", else: "not to" - "Expected #{inspect(subject)} #{to} raise the `#{module}` exception with the message `#{message}`, but the `#{err_module}` exception was raised with the message `#{err_message}`." + { + "Expected #{inspect(subject)} #{to} raise the `#{module}` exception with the message `#{message}`, but the `#{err_module}` exception was raised with the message `#{err_message}`.", + nil + } end end diff --git a/lib/espec/assertions/refute_receive.ex b/lib/espec/assertions/refute_receive.ex index a9427cb2..3feee539 100644 --- a/lib/espec/assertions/refute_receive.ex +++ b/lib/espec/assertions/refute_receive.ex @@ -18,6 +18,9 @@ defmodule ESpec.Assertions.RefuteReceive do end defp error_message(_subject, _pattern, result, _positive) do - "Expected not to receive `#{result}`, but have received." + { + "Expected not to receive `#{result}`, but have received.", + nil + } end end diff --git a/lib/espec/assertions/result/be_error_result.ex b/lib/espec/assertions/result/be_error_result.ex index 62742797..ecc9f4db 100644 --- a/lib/espec/assertions/result/be_error_result.ex +++ b/lib/espec/assertions/result/be_error_result.ex @@ -21,6 +21,6 @@ defmodule ESpec.Assertions.Result.BeErrorResult do defp error_message(tuple, _data, _result, positive) do to = if positive, do: "to", else: "not to" but = if positive, do: "it is not", else: "it is" - "Expected `#{inspect(tuple)}` #{to} be a error result but #{but}." + {"Expected `#{inspect(tuple)}` #{to} be a error result but #{but}.", nil} end end diff --git a/lib/espec/assertions/result/be_ok_result.ex b/lib/espec/assertions/result/be_ok_result.ex index 1ecafc6c..91be053e 100644 --- a/lib/espec/assertions/result/be_ok_result.ex +++ b/lib/espec/assertions/result/be_ok_result.ex @@ -21,6 +21,6 @@ defmodule ESpec.Assertions.Result.BeOkResult do defp error_message(tuple, _data, _result, positive) do to = if positive, do: "to", else: "not to" but = if positive, do: "it is not", else: "it is" - "Expected `#{inspect(tuple)}` #{to} be a success result but #{but}." + {"Expected `#{inspect(tuple)}` #{to} be a success result but #{but}.", nil} end end diff --git a/lib/espec/assertions/string/be_blank.ex b/lib/espec/assertions/string/be_blank.ex index 49ef8327..5f5e8048 100644 --- a/lib/espec/assertions/string/be_blank.ex +++ b/lib/espec/assertions/string/be_blank.ex @@ -19,6 +19,6 @@ defmodule ESpec.Assertions.String.BeBlank do defp error_message(string, _val, _result, positive) do to = if positive, do: "to", else: "not to" but = if positive, do: "it isn't", else: "it is" - "Expected `#{inspect(string)}` #{to} be blank but #{but}." + {"Expected `#{inspect(string)}` #{to} be blank but #{but}.", nil} end end diff --git a/lib/espec/assertions/string/be_printable.ex b/lib/espec/assertions/string/be_printable.ex index b768d68e..86ac79df 100644 --- a/lib/espec/assertions/string/be_printable.ex +++ b/lib/espec/assertions/string/be_printable.ex @@ -19,6 +19,6 @@ defmodule ESpec.Assertions.String.BePrintable do defp error_message(string, _val, _result, positive) do to = if positive, do: "to", else: "not to" but = if positive, do: "it isn't", else: "it is" - "Expected `#{inspect(string)}` #{to} be printable but #{but}." + {"Expected `#{inspect(string)}` #{to} be printable but #{but}.", nil} end end diff --git a/lib/espec/assertions/string/be_valid_string.ex b/lib/espec/assertions/string/be_valid_string.ex index eb8fb53a..8a57dcca 100644 --- a/lib/espec/assertions/string/be_valid_string.ex +++ b/lib/espec/assertions/string/be_valid_string.ex @@ -19,6 +19,6 @@ defmodule ESpec.Assertions.String.BeValidString do defp error_message(string, _val, _result, positive) do to = if positive, do: "to", else: "not to" but = if positive, do: "it isn't", else: "it is" - "Expected `#{inspect(string)}` #{to} be valid but #{but}." + {"Expected `#{inspect(string)}` #{to} be valid but #{but}.", nil} end end diff --git a/lib/espec/assertions/string/end_with.ex b/lib/espec/assertions/string/end_with.ex index a55acd5c..9ac0d915 100644 --- a/lib/espec/assertions/string/end_with.ex +++ b/lib/espec/assertions/string/end_with.ex @@ -38,7 +38,7 @@ defmodule ESpec.Assertions.String.EndWith do if positive do {m, %{diff_fn: fn -> ESpec.Diff.diff(result, val) end}} else - m + {m, nil} end end end diff --git a/lib/espec/assertions/string/start_with.ex b/lib/espec/assertions/string/start_with.ex index fa8a576e..d7dbf2b5 100644 --- a/lib/espec/assertions/string/start_with.ex +++ b/lib/espec/assertions/string/start_with.ex @@ -38,7 +38,7 @@ defmodule ESpec.Assertions.String.StartWith do if positive do {m, %{diff_fn: fn -> ESpec.Diff.diff(result, val) end}} else - m + {m, nil} end end end diff --git a/lib/espec/assertions/throw_term.ex b/lib/espec/assertions/throw_term.ex index b6376f92..f58fbd08 100644 --- a/lib/espec/assertions/throw_term.ex +++ b/lib/espec/assertions/throw_term.ex @@ -39,16 +39,27 @@ defmodule ESpec.Assertions.ThrowTerm do defp error_message(subject, [], term, positive) do to = if positive, do: "to", else: "not to" but = if positive, do: "nothing was thrown", else: "`#{inspect(term)}` was thrown" - "Expected `#{inspect(subject)}` #{to} throw term, but #{but}." + + { + "Expected `#{inspect(subject)}` #{to} throw term, but #{but}.", + nil + } end defp error_message(subject, [data], {term, false}, positive) do to = if positive, do: "to", else: "not to" but = if positive, do: "nothing was thrown", else: "the `#{inspect(term)}` was thrown" - "Expected `#{inspect(subject)}` #{to} throw #{inspect(data)}, but #{but}." + + { + "Expected `#{inspect(subject)}` #{to} throw #{inspect(data)}, but #{but}.", + nil + } end defp error_message(subject, [data], {term, true}, _positive) do - "Expected `#{inspect(subject)}` to throw #{inspect(data)}, but the `#{inspect(term)}` was thrown." + { + "Expected `#{inspect(subject)}` to throw #{inspect(data)}, but the `#{inspect(term)}` was thrown.", + nil + } end end diff --git a/lib/espec/extension/datetime_extension.ex b/lib/espec/extension/datetime_extension.ex index 93d0f26d..4b25477f 100644 --- a/lib/espec/extension/datetime_extension.ex +++ b/lib/espec/extension/datetime_extension.ex @@ -97,10 +97,6 @@ defmodule DateTime.Extension do case from_naive(naive_datetime, time_zone) do {:ok, datetime} -> datetime - - {:error, reason} -> - raise ArgumentError, - "cannot parse #{inspect(naive_datetime)} to datetime, reason: #{inspect(reason)}" end end end diff --git a/mix.exs b/mix.exs index 42a8019a..c41528bf 100644 --- a/mix.exs +++ b/mix.exs @@ -24,10 +24,10 @@ defmodule ESpec.Mixfile do defp deps do [ - {:meck, "~> 0.9"}, + {:meck, "~> 1.0"}, {:credo, "~> 1.7", only: [:dev, :test], runtime: false}, # Docs - {:ex_doc, "~> 0.31", only: [:docs, :dev]} + {:ex_doc, "~> 0.38", only: [:docs, :dev]} ] end diff --git a/mix.lock b/mix.lock index 3f55bb8c..b356636d 100644 --- a/mix.lock +++ b/mix.lock @@ -2,13 +2,13 @@ "bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"}, "credo": {:hex, :credo, "1.7.3", "05bb11eaf2f2b8db370ecaa6a6bda2ec49b2acd5e0418bc106b73b07128c0436", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "35ea675a094c934c22fb1dca3696f3c31f2728ae6ef5a53b5d648c11180a4535"}, "earmark": {:hex, :earmark, "1.3.1", "73812f447f7a42358d3ba79283cfa3075a7580a3a2ed457616d6517ac3738cb9", [:mix], [], "hexpm", "000aaeff08919e95e7aea13e4af7b2b9734577b3e6a7c50ee31ee88cab6ec4fb"}, - "earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"}, - "ex_doc": {:hex, :ex_doc, "0.31.1", "8a2355ac42b1cc7b2379da9e40243f2670143721dd50748bf6c3b1184dae2089", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.1", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "3178c3a407c557d8343479e1ff117a96fd31bafe52a039079593fb0524ef61b0"}, + "earmark_parser": {:hex, :earmark_parser, "1.4.44", "f20830dd6b5c77afe2b063777ddbbff09f9759396500cdbe7523efd58d7a339c", [:mix], [], "hexpm", "4778ac752b4701a5599215f7030989c989ffdc4f6df457c5f36938cc2d2a2750"}, + "ex_doc": {:hex, :ex_doc, "0.38.2", "504d25eef296b4dec3b8e33e810bc8b5344d565998cd83914ffe1b8503737c02", [:mix], [{:earmark_parser, "~> 1.4.44", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "732f2d972e42c116a70802f9898c51b54916e542cc50968ac6980512ec90f42b"}, "file_system": {:hex, :file_system, "1.0.0", "b689cc7dcee665f774de94b5a832e578bd7963c8e637ef940cd44327db7de2cd", [:mix], [], "hexpm", "6752092d66aec5a10e662aefeed8ddb9531d79db0bc145bb8c40325ca1d8536d"}, "jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"}, - "makeup": {:hex, :makeup, "1.1.1", "fa0bc768698053b2b3869fa8a62616501ff9d11a562f3ce39580d60860c3a55e", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5dc62fbdd0de44de194898b6710692490be74baa02d9d108bc29f007783b0b48"}, - "makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"}, - "makeup_erlang": {:hex, :makeup_erlang, "0.1.3", "d684f4bac8690e70b06eb52dad65d26de2eefa44cd19d64a8095e1417df7c8fd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "b78dc853d2e670ff6390b605d807263bf606da3c82be37f9d7f68635bd886fc9"}, - "meck": {:hex, :meck, "0.9.0", "cb40c223cf403db2d09def59d32d3682074ebecceb64f3e6f6c4477458df124d", [:rebar3], [], "hexpm", "f813e90dd0b89b2516a0201a355e84b1abc78b5751aa0cbf669a9d85a810ac63"}, - "nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"}, + "makeup": {:hex, :makeup, "1.2.1", "e90ac1c65589ef354378def3ba19d401e739ee7ee06fb47f94c687016e3713d1", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "d36484867b0bae0fea568d10131197a4c2e47056a6fbe84922bf6ba71c8d17ce"}, + "makeup_elixir": {:hex, :makeup_elixir, "1.0.1", "e928a4f984e795e41e3abd27bfc09f51db16ab8ba1aebdba2b3a575437efafc2", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "7284900d412a3e5cfd97fdaed4f5ed389b8f2b4cb49efc0eb3bd10e2febf9507"}, + "makeup_erlang": {:hex, :makeup_erlang, "1.0.2", "03e1804074b3aa64d5fad7aa64601ed0fb395337b982d9bcf04029d68d51b6a7", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "af33ff7ef368d5893e4a267933e7744e46ce3cf1f61e2dccf53a111ed3aa3727"}, + "meck": {:hex, :meck, "1.0.0", "24676cb6ee6951530093a93edcd410cfe4cb59fe89444b875d35c9d3909a15d0", [:rebar3], [], "hexpm", "680a9bcfe52764350beb9fb0335fb75fee8e7329821416cee0a19fec35433882"}, + "nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [:mix], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"}, } diff --git a/spec/allow_accept_spec.exs b/spec/allow_accept_spec.exs index 805db648..3ee0c706 100644 --- a/spec/allow_accept_spec.exs +++ b/spec/allow_accept_spec.exs @@ -6,7 +6,7 @@ defmodule AllowAcceptSpec do describe "allow(module).to accept(name, func)" do before do: allow(SomeModule) |> to(accept(:func, fn a -> "mock! #{a}" end)) - it do: expect(SomeModule.func(1)) |> to(eq "mock! 1") + it do: expect(apply(SomeModule, :func, [1])) |> to(eq "mock! 1") end describe "allow(module).to accept(name1: func1, name2: func2)" do @@ -20,7 +20,7 @@ defmodule AllowAcceptSpec do ) end - it do: expect(SomeModule.func(1)) |> to(eq "mock! 1") - it do: expect(SomeModule.func2()) |> to(eq "mock! func2") + it do: expect(apply(SomeModule, :func, [1])) |> to(eq "mock! 1") + it do: expect(apply(SomeModule, :func2, [])) |> to(eq "mock! func2") end end diff --git a/spec/assertions/accepted_spec.exs b/spec/assertions/accepted_spec.exs index 0a45f43f..8355d380 100644 --- a/spec/assertions/accepted_spec.exs +++ b/spec/assertions/accepted_spec.exs @@ -6,6 +6,7 @@ defmodule AcceptedSpec do defmodule SomeModule do def f, do: :f def m, do: :m + def func(a, b), do: a - b end |> write_beam diff --git a/spec/assertions/eq_spec.exs b/spec/assertions/eq_spec.exs index 6c0a8438..53186dc5 100644 --- a/spec/assertions/eq_spec.exs +++ b/spec/assertions/eq_spec.exs @@ -26,18 +26,6 @@ defmodule ESpec.Assertions.EqSpec do it_behaves_like(CheckErrorSharedSpec) end - context "with complex `to`" do - before do - {:shared, - expectation: fn -> expect(%{a: 2, b: 3, c: 4}) |> to(eq(%{a: 2, b: 4})) end, - message: - "Expected `#{inspect(%{a: 2, b: 3, c: 4})}` to equal (==) `%{a: 2, b: 4}`, but it doesn't.", - extra: true} - end - - it_behaves_like(CheckErrorSharedSpec) - end - context "with `not_to`" do before do {:shared, diff --git a/spec/assertions/map/have_key_spec.exs b/spec/assertions/map/have_key_spec.exs index f2f6f5e7..254c257f 100644 --- a/spec/assertions/map/have_key_spec.exs +++ b/spec/assertions/map/have_key_spec.exs @@ -1,17 +1,17 @@ defmodule ESpec.Assertions.Map.HaveKeySpec do use ESpec, async: true - subject %{a: 1, b: 2} + subject %{a: 1} context "Success" do it "checks success with `to`" do message = should(have_key :a) - expect(message) |> to(eq "`%{a: 1, b: 2}` has key `:a`.") + expect(message) |> to(eq "`%{a: 1}` has key `:a`.") end it "checks success with `not_to`" do message = should_not(have_key :c) - expect(message) |> to(eq "`%{a: 1, b: 2}` doesn't have key `:c`.") + expect(message) |> to(eq "`%{a: 1}` doesn't have key `:c`.") end end @@ -20,7 +20,7 @@ defmodule ESpec.Assertions.Map.HaveKeySpec do before do {:shared, expectation: fn -> should(have_key :c) end, - message: "Expected `%{a: 1, b: 2}` to have key `:c` but it doesn't have."} + message: "Expected `%{a: 1}` to have key `:c` but it doesn't have."} end it_behaves_like(CheckErrorSharedSpec) @@ -30,7 +30,7 @@ defmodule ESpec.Assertions.Map.HaveKeySpec do before do {:shared, expectation: fn -> should_not(have_key :a) end, - message: "Expected `%{a: 1, b: 2}` not to have key `:a` but it has."} + message: "Expected `%{a: 1}` not to have key `:a` but it has."} end it_behaves_like(CheckErrorSharedSpec) diff --git a/spec/assertions/map/have_value_spec.exs b/spec/assertions/map/have_value_spec.exs index a5edb4d6..a4912efd 100644 --- a/spec/assertions/map/have_value_spec.exs +++ b/spec/assertions/map/have_value_spec.exs @@ -1,17 +1,17 @@ defmodule ESpec.Assertions.Map.HaveValueSpec do use ESpec, async: true - subject %{a: 1, b: 2} + subject %{a: 1} context "Success" do it "checks success with `to`" do message = should(have_value 1) - expect(message) |> to(eq "`%{a: 1, b: 2}` has value `1`.") + expect(message) |> to(eq "`%{a: 1}` has value `1`.") end it "checks success with `not_to`" do message = should_not(have_value 3) - expect(message) |> to(eq "`%{a: 1, b: 2}` doesn't have value `3`.") + expect(message) |> to(eq "`%{a: 1}` doesn't have value `3`.") end end @@ -20,7 +20,7 @@ defmodule ESpec.Assertions.Map.HaveValueSpec do before do {:shared, expectation: fn -> should(have_value 3) end, - message: "Expected `%{a: 1, b: 2}` to have value `3` but it doesn't have."} + message: "Expected `%{a: 1}` to have value `3` but it doesn't have."} end it_behaves_like(CheckErrorSharedSpec) @@ -30,7 +30,7 @@ defmodule ESpec.Assertions.Map.HaveValueSpec do before do {:shared, expectation: fn -> should_not(have_value 1) end, - message: "Expected `%{a: 1, b: 2}` not to have value `1` but it has."} + message: "Expected `%{a: 1}` not to have value `1` but it has."} end it_behaves_like(CheckErrorSharedSpec) diff --git a/spec/described_module_spec.exs b/spec/described_module_spec.exs index 7758104a..c125045b 100644 --- a/spec/described_module_spec.exs +++ b/spec/described_module_spec.exs @@ -8,5 +8,5 @@ defmodule TheSpecModuleSpec do it do: expect(@described_module |> to(eq Elixir.TheSpecModule)) it do: expect(described_module() |> to(eq Elixir.TheSpecModule)) - it do: expect(described_module().test |> to(eq :test)) + it do: expect(apply(described_module(), :test, []) |> to(eq :test)) end diff --git a/spec/doc_test_spec.exs b/spec/doc_test_spec.exs index a7b5a917..066854e7 100644 --- a/spec/doc_test_spec.exs +++ b/spec/doc_test_spec.exs @@ -33,43 +33,10 @@ defmodule ESpec.DocTestTest.Mod1 do end |> ESpec.TestHelpers.write_beam() -defmodule ESpec.DocTestTest.ExceptionInterpolation do - @moduledoc """ - iex> raise ArgumentError, message: ~S'Check for "string"' - ** (ArgumentError) Check for "string" - - iex> raise ArgumentError, message: "Check for 'string'" - ** (ArgumentError) Check for 'string' - - iex> raise ArgumentError, message: "Check for |string|" - ** (ArgumentError) Check for |string| - - iex> raise ArgumentError, message: "Check for /string/" - ** (ArgumentError) Check for /string/ - - iex> raise ArgumentError, message: "Check for (string)" - ** (ArgumentError) Check for (string) - - iex> raise ArgumentError, message: "Check for [string]" - ** (ArgumentError) Check for [string] - - iex> raise ArgumentError, message: "Check for {string}" - ** (ArgumentError) Check for {string} - - iex> raise ArgumentError, message: "Check for " - ** (ArgumentError) Check for - - iex> raise ArgumentError, message: "Check for a very, very, very, very, very, very, very, very, very, very, very, very, very, very, very long string" - ** (ArgumentError) Check for a very, very, very, very, very, very, very, very, very, very, very, very, very, very, very long string - """ -end -|> ESpec.TestHelpers.write_beam() - defmodule DocTestSpec do use ESpec doctest ESpec.DocTestTest.Mod1 - doctest ESpec.DocTestTest.ExceptionInterpolation - it do: expect(ESpec.DocTestTest.Mod1.f() |> to(eq :f)) + it do: expect(ESpec.DocTestTest.Mod1.f()) |> to(eq :f) end diff --git a/spec/mock_spec.exs b/spec/mock_spec.exs index b818af67..ae307230 100644 --- a/spec/mock_spec.exs +++ b/spec/mock_spec.exs @@ -5,7 +5,10 @@ defmodule MockSpec do defmodule SomeModule do def f, do: :f + def f(_a), do: :a def m, do: :m + def x, do: :x + def q, do: :q def f1(a), do: a def f2(a, b), do: "#{a} and #{b}" @@ -20,12 +23,12 @@ defmodule MockSpec do allow SomeModule |> to(accept(x: fn -> :y end, q: fn -> :w end)) end - it do: expect(SomeModule.f(1) |> to(eq "mock! 1")) - it do: expect(SomeModule.x() |> to(eq :y)) - it do: expect(SomeModule.q() |> to(eq :w)) + it do: expect(apply(SomeModule, :f, [1]) |> to(eq "mock! 1")) + it do: expect(apply(SomeModule, :x, []) |> to(eq :y)) + it do: expect(apply(SomeModule, :q, []) |> to(eq :w)) it "SomeModule.m is not mocked" do - expect(SomeModule.m() |> to(eq :m)) + expect(apply(SomeModule, :m, []) |> to(eq :m)) end end @@ -35,12 +38,12 @@ defmodule MockSpec do allow SomeModule |> to(accept(x: fn -> :y end, q: fn -> :w end)) end - it do: expect(SomeModule.f(1) |> to(eq "mock! 1")) - it do: expect(SomeModule.x() |> to(eq :y)) - it do: expect(SomeModule.q() |> to(eq :w)) + it do: expect(apply(SomeModule, :f, [1]) |> to(eq "mock! 1")) + it do: expect(apply(SomeModule, :x, []) |> to(eq :y)) + it do: expect(apply(SomeModule, :q, []) |> to(eq :w)) it "SomeModule.m is not mocked" do - expect(SomeModule.m() |> to(eq :m)) + expect(apply(SomeModule, :m, []) |> to(eq :m)) end end @@ -51,10 +54,10 @@ defmodule MockSpec do allow(SomeModule) |> to(accept([:x, :q])) end - it do: expect(SomeModule.f()) |> to(be_nil()) + it do: expect(apply(SomeModule, :f, [])) |> to(be_nil()) - it do: expect(SomeModule.x()) |> to(be_nil()) - it do: expect(SomeModule.q(10)) |> to(be_nil()) + it do: expect(apply(SomeModule, :x, [])) |> to(be_nil()) + it do: expect(apply(SomeModule, :q, [10])) |> to(be_nil()) end context "with new syntax" do @@ -63,23 +66,15 @@ defmodule MockSpec do allow SomeModule |> to(accept([:x, :q])) end - it do: expect(SomeModule.f() |> to(be_nil())) + it do: expect(apply(SomeModule, :f, [])) |> to(be_nil()) - it do: expect(SomeModule.x() |> to(be_nil())) - it do: expect(SomeModule.q(10) |> to(be_nil())) + it do: expect(apply(SomeModule, :x, [])) |> to(be_nil()) + it do: expect(apply(SomeModule, :q, [10])) |> to(be_nil()) end end context "without mock" do - it do: expect(SomeModule.f()) |> to(eq(:f)) - end - - context "mock in another process doesn't mock functions in current process" do - before do - spawn(fn -> allow(SomeModule).to(accept(:f, fn a -> "mock! #{a}" end)) end) - end - - # it do: expect(SomeModule.f).to eq(:f) + it do: expect(apply(SomeModule, :f, [])) |> to(eq(:f)) end context "passthrough" do diff --git a/spec/shared_spec.exs b/spec/shared_spec.exs index 67e31764..2e0d57a2 100644 --- a/spec/shared_spec.exs +++ b/spec/shared_spec.exs @@ -24,11 +24,6 @@ defmodule SharedSpec do it do: b() |> should(eq 2) end - - describe "let and let form outer module" do - it do: shared.outer_let() |> should(eq :outer_let) - it do: shared.outer_let!() |> should(eq :outer_let!) - end end defmodule UseSharedSpecSpec do diff --git a/spec/support/assertions/be_divisor_of_assertion.ex b/spec/support/assertions/be_divisor_of_assertion.ex index 8b12574a..2fcb7c7c 100644 --- a/spec/support/assertions/be_divisor_of_assertion.ex +++ b/spec/support/assertions/be_divisor_of_assertion.ex @@ -14,6 +14,7 @@ defmodule BeDivisorOfAssertion do defp error_message(subject, number, result, positive) do to = if positive, do: "to", else: "not to" - "Expected `#{inspect(subject)}` #{to} be the divisor of `#{number}`, but the remainder is '#{result}'." + {"Expected `#{inspect(subject)}` #{to} be the divisor of `#{number}`, but the remainder is '#{result}'.", + nil} end end diff --git a/spec/support/assertions/be_odd_assertion.ex b/spec/support/assertions/be_odd_assertion.ex index 0630dcd5..f81ebf8c 100644 --- a/spec/support/assertions/be_odd_assertion.ex +++ b/spec/support/assertions/be_odd_assertion.ex @@ -13,6 +13,8 @@ defmodule BeOddAssertion do defp error_message(subject, [], result, positive) do to = if positive, do: "to", else: "not to" - "Expected `#{inspect(subject)}` #{to} be the odd number, but the remainder is '#{result}'." + + {"Expected `#{inspect(subject)}` #{to} be the odd number, but the remainder is '#{result}'.", + nil} end end diff --git a/test/assertions/map/have_test.exs b/test/assertions/map/have_test.exs index c848b27f..8af28e81 100644 --- a/test/assertions/map/have_test.exs +++ b/test/assertions/map/have_test.exs @@ -23,13 +23,13 @@ defmodule Map.HaveTest do end context "Error" do - it do: expect(map()).to_not(have({:foo, "bar"})) - it do: expect(map()).to_not(have(foo: "bar")) - it do: expect(map()).to(have(4)) + it do: expect(map()) |> to_not(have({:foo, "bar"})) + it do: expect(map()) |> to_not(have(foo: "bar")) + it do: expect(map()) |> to(have(4)) - it do: expect(struct()).to_not(have({:foo, "bar"})) - it do: expect(struct()).to_not(have(foo: "bar")) - it do: expect(struct()).to(have(4)) + it do: expect(struct()) |> to_not(have({:foo, "bar"})) + it do: expect(struct()) |> to_not(have(foo: "bar")) + it do: expect(struct()) |> to(have(4)) end end diff --git a/test/described_module_test.exs b/test/described_module_test.exs index 46df13e2..85c3cefc 100644 --- a/test/described_module_test.exs +++ b/test/described_module_test.exs @@ -12,6 +12,6 @@ defmodule ESpec.DescribedModuleTest do test ".described_module" do assert TheSpecModuleSpec.described_module() == TheSpecModule - assert TheSpecModuleSpec.described_module().test == :test + assert apply(TheSpecModuleSpec.described_module(), :test, []) == :test end end diff --git a/test/docs/exception_test.exs b/test/docs/exception_test.exs index 2c8d5983..e46ada80 100644 --- a/test/docs/exception_test.exs +++ b/test/docs/exception_test.exs @@ -9,21 +9,11 @@ defmodule ESpec.Docs.ExceptionTest do setup do examples = ESpec.DocTest.ExceptionsSpec.examples() - {:ok, ex1: Enum.at(examples, 0), ex2: Enum.at(examples, 1), ex3: Enum.at(examples, 2)} + {:ok, ex1: Enum.at(examples, 0)} end test "ex1", context do ex = ESpec.ExampleRunner.run(context[:ex1]) assert ex.status == :success end - - test "ex2", context do - ex = ESpec.ExampleRunner.run(context[:ex2]) - assert ex.status == :success - end - - test "ex3", context do - ex = ESpec.ExampleRunner.run(context[:ex3]) - assert ex.status == :failure - end end diff --git a/test/let/leaking_subject_test.exs b/test/let/leaking_subject_test.exs index 6cb0b777..c293c228 100644 --- a/test/let/leaking_subject_test.exs +++ b/test/let/leaking_subject_test.exs @@ -13,7 +13,7 @@ defmodule LeakingSubjectTest do ESpec.Context.describe "second" do it do: should(be_empty()) it do: is_expected() |> to(be_empty()) - it do: is_expected().to(be_empty()) + it do: is_expected() |> to(be_empty()) end end diff --git a/test/test_modules/docs/doc_test_modules.ex b/test/test_modules/docs/doc_test_modules.ex index 082299e6..ae54396f 100644 --- a/test/test_modules/docs/doc_test_modules.ex +++ b/test/test_modules/docs/doc_test_modules.ex @@ -65,12 +65,6 @@ defmodule TestModules.Docs.DocTestModules do iex(1)> apply(Kernel, :+, [:a, 1]) ** (ArithmeticError) bad argument in arithmetic expression :erlang.+(:a, 1) - - iex> raise ArithmeticError - ** (ArithmeticError) bad argument in arithmetic expression - - iex> 1 + 1 - ** (ArithmeticError) bad argument in arithmetic expression """ def f, do: :f end