How to upload files to a path other than lib (Elixir)

I am trying to use an assistant for a task in testing. My folder structure is as follows:

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

And now what I want to do is

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 using this (inside the test):

HelperModuler.calling_function(args)

But I get this error:

 (UndefinedFunctionError) undefined function HelperModuler.calling_function/1 (module HelperModuler is not available)
+4
source share
3 answers

You can also load code during test execution using Code.require_filetest.helpers in the configuration.

 Code.require_file("test/provider_test/helpers/helper.exs")
+1
source

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

  • Put it in a file with the extension .ex.
  • , , elixirc_paths , MyApp.Mixfile.project/0 mix.exs.

, , Phoenix test/support :test Mix env 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"]
+7
def project do
[app: :example,
 version: "0.1.0",
 elixir: "~> 1.4",
 build_embedded: Mix.env == :prod,
 start_permanent: Mix.env == :prod,
 elixirc_paths: ["lib", "path_to_your_src"],
 deps: deps()]
end

Add this line elixirc_paths: ["lib", "path_to_your_src"],to return your function projectinmix.exs

0
source

Source: https://habr.com/ru/post/1652472/


All Articles