I have a group of acceptance tests I've created in my faux blog phoenix app. There's some duplicated logic between them I'd like to move to a helpers module to keep things DRY.
Here is the directory structure:
test/acceptance/post
├── create_test.exs
├── delete_test.exs
├── helpers.exs
├── index_test.exs
└── update_test.exs
The helpers.exs
file is where I'd like to stick the duplicated acceptance test logic. It looks something like:
defmodule Blog.Acceptance.Post.Helpers do
def navigate_to_posts_index_page do
# some code
end
end
Then in one of my test files, say index_test.exs
, I'd like to import the helpers module to use it's methods:
defmodule Blog.Acceptance.Post.IndexTest do
import Blog.Acceptance.Post.Helpers
end
However, I'm getting this error:
** (CompileError) test/acceptance/post/index_test.exs:7: module Blog.Acceptance.Post.Helpers is not loaded and could not be found
How do I get access to or load the helper module in my test files?
To make the test_helpers.exs
Helpers module available, you'd need to use Code.require_file
to load it; however, in this case phoenix configured your project to compile .ex
files in test/support
into the project exactly for cases like this. So if you place your module in test/support/test_helpers.ex
, it will be compiled with your project and available to all test files without having to Code.require_file
it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With