FarhanSyedain
Io.puts and Logger not working along with errors not being dispayed
Here is my primary test file
ExUnit.start()
Ecto.Adapters.SQL.Sandbox.mode(Core.Repo, :manual)
Faker.start()
defmodule ChatBackendTest do
use ExUnit.Case, async: true
alias ChatBackendTest.Support.Factory
use ChatBackendTest.Support.EctoTemplate
require Logger
alias Core.Schema.User
test "create user" do
_ = Factory.create(User, %{})
IO.puts("Should Print this too")
#
end
end
And here is the factory file
defmodule ChatBackendTest.Support.Factory do
alias Authentication.Schema.User
alias Core.Repo
require Logger
def create(User, attrs) do
Logger.error("Should print on console")
user_data =
Keyword.merge(
[
phone_number: Faker.Phone.PtBr.phone(),
uuid: Faker.UUID.v4(),
last_seen: NaiveDateTime.utc_now(),
registration_id: Faker.UUID.v4()
],
attrs
)
try do
User |> struct(user_data) |> Repo.insert(returning: true)
rescue
e ->
Logger.error("Error: #{inspect(e)}")
end
end
end
The problem : Io.puts or any other code is working before i call the factory.create method. However after factory.create nothing is executing , when when i put a IO.puts as the first statemetn inside the create function, nothing was printed. No error was shown in the console either.
However, when i copy the create code and put it directly in the test file. The resuce thing handles the error and gives me some error on struct.
The question being, what’s wrong with elxir not showing errors. How do i make it that all the erros are logged in instead of the test being half executed.
Popular in Questions
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
Hi all,
Trying to get some more clarity over utc_datetime and naive_datetime for Ecto:
https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
Hello, I have map which I want to convert it to string like this:
the map:
%{last_name: "tavakkoli", name: "shahryar"}
the string I ne...
New
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
Sometimes I want to check if the input into a function is not a blank string.
My first approach:
defmodule Example do
def do_stuff(s...
New
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: )
Hello all, this is ...
New
I have a super simple question about elixir - how would I take a file like this
foo bar baz
and output a new file that enumerates th...
New
Other popular topics
Hello!
tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability.
After spen...
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
pro...
New
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!)
This post collects co...
New
I would like to know what is the best IDE for elixir development?
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New







