newelixiruser

newelixiruser

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?

Showing Posts 1 to 6

cevado

cevado

it seems that you have 2 implementations of the module App.Settings, one doesn’t define the behaviour App.SettingsBehaviour. one might be overwriting the other.

also, are you defining the mock in your test_helper.exs file?

newelixiruser

newelixiruser OP

Sorry, the module name copy was a typo of my part. I corrected it.
Yes i am defining the mocks in supports/mocks.ex!!

cevado

cevado

how is your config for search_enabled in the test config file

newelixiruser

newelixiruser OP

I updated my post with the config/test.exs content

cevado

cevado

  • App.Settings doesn’t call any function, just get a value from your Application config store.
  • App.BoundSettings doesn’t implement the behaviour.
  • UnexpectedCallError usually 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.

newelixiruser

newelixiruser OP

One of the expectation was missing making load of tests fails

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews