Current section
Files
Jump to
Current section
Files
lib/nldoc/test/logs.ex
defmodule NLdoc.Test.Logs do
@moduledoc """
This module helps with capturing log output in tests.
"""
@doc """
Decodes each line in the given log string with `Jason.decode/1`.
## Examples
iex> logs = "{\\"message\\": \\"test\\"}\\n{\\"message\\": \\"another test\\"}\\n\\n"
iex> logs |> NLdoc.Test.Logs.decode_json()
[%{"message" => "test"}, %{"message" => "another test"}]
iex> [%{"message" => "test"}] |> match?(logs |> NLdoc.Test.Logs.decode_json())
"""
@spec decode_json(String.t()) :: [map()]
def decode_json(logs) do
logs |> String.split("\n", trim: true) |> Enum.map(&Jason.decode!/1)
end
end