If you move the function definition outside of the describe/2 block, it will be available. You may want to check the documentation for describe/2, specifically the section on hierarchies, it may fit your needs.
I think there is probably a debate on whether or not what you are trying to do should be allowed.
I have two describe blocks. They both need to use user_fixture. I moved that definition out of the first block, deleted the definition of user_fixture2, and now have two calls to ``user_fixture`: on in the first describe block, the other in the second. The error comes in the second block.
Do you have a repository with a small example to show this behaviour? Because after doing a small test, defining the function in the describe/2 block works as expected.
Alright. I am not entirely sure the reason behind it, but it turns out you cannot call the function in the describe/2 block, but you can call it in the test/1 block. I am not really sure of the limitations on this because I was able to call List.first/1 without an issue. So maybe it is limited to functions defined in the same exs file?
Either way, what you should be doing is using a setup_all/1 block in order to do something for all of the tests within the describe/2.
There’s a better way to explain what I’m about to say, but you’re trying to assign a variable in the AST using a method that’s also a leaf in the same tree.
You will have to declare the method in a new module entirely or use it in a test or setup block of that module.
Thanks! setup_all did the trick … it needed code as indicated below:
setup_all do
# Explicitly get a connection before each test
# By default the test is wrapped in a transaction
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Koko.Repo)
# The :shared mode allows a process to share
# its connection with any other process automatically
Ecto.Adapters.SQL.Sandbox.mode(Koko.Repo, { :shared, self() })
:ok
end