Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How load files in a path different than lib (Elixir)

Tags:

testing

elixir

I trying to use a helper for a task in a testing. My folder structure is like this:

config/
lib/
test/
test/test_helper.exs
test/provider_test/(the test files are here)

And now what I want to do is this

config/
lib/
test/
test/test_helper.exs
test/provider_test/(the test files are here)
test/provider_test/helpers/(the helpers files... more or less, one for helper)

I tried to use this (inside a test):

HelperModuler.calling_function(args)

But I get this error:

 (UndefinedFunctionError) undefined function HelperModuler.calling_function/1 (module HelperModuler is not available)
like image 748
Eloy Fernández Franco Avatar asked Aug 25 '16 13:08

Eloy Fernández Franco


1 Answers

To make a module available in all tests, you need to do 2 things:

  1. Put it in a file with the extension .ex.
  2. Add the folder containing that file to the elixirc_paths key of the value return from MyApp.Mixfile.project/0 in mix.exs.

For example, here's how Phoenix handles adding test/support for just the :test Mix env in mix.exs:

def project do
  [...,
   elixirc_paths: elixirc_paths(Mix.env),
   ...]
end

# Specifies which paths to compile per environment.
defp elixirc_paths(:test), do: ["lib", "web", "test/support"]
defp elixirc_paths(_),     do: ["lib", "web"]
like image 113
Dogbert Avatar answered Oct 26 '22 13:10

Dogbert