newelixiruser
Mox return a UnexpectedCallError
Hi,
I’m trying to test my config settings.
To do that, i use a module that load them: like this
defmodule App.SettingsBehaviour do
@moduledoc """
Define the behavior for accessing environment variable settings
"""
@callback is_search_enabled :: boolean
end
defmodule App.BoundSettings do
@options Application.get_env(:app, :options, App.Settings)
def is_search_enabled do
@options.is_search_enabled
end
end
defmodule App.Settings do
@behaviour App.SettingsBehaviour
@impl App.SettingsBehaviour
def is_search_enabled, do: Application.get_env(:app, :search_enabled, false)
end
config/test.exs
config :app, :options, App.OptionsMock
config :app, search_enabled: true
I have a liveview controller calling App.Settings, and when i try to mock it it returns UnexpectedCallError. Does anyone understand what could fail here?
Marked As Solved
cevado
App.Settingsdoesn’t call any function, just get a value from your Application config store.App.BoundSettingsdoesn’t implement the behaviour.UnexpectedCallErrorusually means that you’re calling the the mock module without setting any expectation on it.
given the context you provided, code paths that use AppBoundSettings doesn’t have a expectation on App.OptionsMock.
Popular in Questions
Hi! May someone helps me, please!
I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
I have followed this StackOverflow post to install the specific version of Erlang.
And When I am running mix ecto.setup then getting fol...
New
Hi,
is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir
iex(2)...
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
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
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
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch.
This project took far...
New
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
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
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New







