Get rid of the koan prefix
This commit is contained in:
@@ -8,7 +8,7 @@ defmodule Display do
|
||||
IO.puts("Now meditate upon #{display_module(module)}")
|
||||
IO.puts("---------------------------------------")
|
||||
IO.puts(format_cyan(last_failure_location))
|
||||
IO.puts(display_koan(name))
|
||||
IO.puts(name)
|
||||
IO.puts(format_red(Macro.to_string(expr)))
|
||||
end
|
||||
|
||||
@@ -55,8 +55,4 @@ defmodule Display do
|
||||
defp display_module(module) do
|
||||
Module.split(module) |> List.last
|
||||
end
|
||||
|
||||
defp display_koan(name) do
|
||||
String.replace(to_string(name), Koans.prefix, "")
|
||||
end
|
||||
end
|
||||
|
||||
13
lib/koans.ex
13
lib/koans.ex
@@ -1,9 +1,6 @@
|
||||
defmodule Koans do
|
||||
@prefix "koan: "
|
||||
|
||||
defmacro koan(name, body) do
|
||||
compiled_name = :"#{prefix}#{name}"
|
||||
|
||||
compiled_name = String.to_atom(name)
|
||||
quote do
|
||||
@koans unquote(compiled_name)
|
||||
def unquote(compiled_name)() do
|
||||
@@ -24,16 +21,10 @@ defmodule Koans do
|
||||
import Koans
|
||||
import BlankAssertions
|
||||
|
||||
@before_compile KoansBuilder
|
||||
@before_compile Koans
|
||||
end
|
||||
end
|
||||
|
||||
def prefix do
|
||||
@prefix
|
||||
end
|
||||
end
|
||||
|
||||
defmodule KoansBuilder do
|
||||
defmacro __before_compile__(env) do
|
||||
koans = Module.get_attribute(env.module, :koans) |> Enum.reverse
|
||||
quote do
|
||||
|
||||
@@ -28,8 +28,7 @@ defmodule Runner do
|
||||
def run_module(module) do
|
||||
Display.considering(module)
|
||||
|
||||
koans = extract_koans_from(module)
|
||||
|
||||
koans = module.all_koans
|
||||
passed = Enum.take_while(koans, fn(name) ->
|
||||
run_koan(module, name) == :passed
|
||||
end)
|
||||
@@ -49,13 +48,4 @@ defmodule Runner do
|
||||
:failed
|
||||
end
|
||||
end
|
||||
|
||||
defp extract_koans_from(module) do
|
||||
module.all_koans
|
||||
|> Enum.filter(&koan?/1)
|
||||
end
|
||||
|
||||
defp koan?(fun_name) do
|
||||
String.starts_with?(to_string(fun_name), Koans.prefix)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user