From 395182c68d8c0cff30256ea0780f049fe5c9ae16 Mon Sep 17 00:00:00 2001 From: Felipe Sere Date: Sun, 10 Apr 2016 20:53:10 +0100 Subject: [PATCH] Fixes the reported line for failures using assert_receive It needed to be turned into a macro and some tinkering with external vars was needed. --- lib/blank_assertions.ex | 17 ++++++++--------- lib/koans.ex | 3 ++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/blank_assertions.ex b/lib/blank_assertions.ex index 7458040..bcc8225 100644 --- a/lib/blank_assertions.ex +++ b/lib/blank_assertions.ex @@ -1,6 +1,4 @@ defmodule BlankAssertions do - require ExUnit.Assertions - defmacro assert(expr) do if contains_blank?(expr) do code = Macro.escape(expr) @@ -27,14 +25,15 @@ defmodule BlankAssertions do end end - def assert_receive(expr) do - if expr == :__ do - raise ExUnit.AssertionError, expr: expr + defmacro assert_receive(expr) do + code = Macro.escape(expr) + if contains_blank?(expr) do + quote do + raise ExUnit.AssertionError, expr: {:assert_receive, [], [unquote(code)]} + end else - receive do - ^expr -> true - after - 100 -> flunk("No message matching #{expr} found in mailbox") + quote do + ExUnit.Assertions.assert_receive(var!(expr), 100) end end end diff --git a/lib/koans.ex b/lib/koans.ex index 0d0305b..2465e98 100644 --- a/lib/koans.ex +++ b/lib/koans.ex @@ -41,13 +41,14 @@ defmodule Koans do end defp create_vars(amount) do - Enum.map(0..amount, fn (idx) -> quote do: elem(converted, unquote(idx)) end) + for id <- 0..amount, do: quote do: elem(converted, unquote(id)) end defmacro __using__(_opts) do quote do @compile :nowarn_unused_vars Module.register_attribute(__MODULE__, :koans, accumulate: true) + require ExUnit.Assertions import Koans import BlankAssertions