Where do the post and get comes from in the following test?

I’m using Mastering Phoenix (Phoenix inside out) by @shankardevy .
There is the following test on page # 189, to test the persistence of user session.

on line # 15 it’s setting the @valid_attrs module attributes to the session using a post request to the /login path, then on line # 16 it’s making a get request to the root path to see if the attributes are there in the session.
I know how does it work, but I don’t know where from the post and get functions come in this test file. Because when I looked for it in the iex through h post, it said No documentation for Kernel.post was found.

It probably comes from use MangoWeb.ConnCase, which probably imports Phoenix.ConnTest.

Check out test/support/conn_case.ex.

2 Likes

Oh, when I read the file from the top I read the use as alias :grinning: and I expected a function like ConnCase.post or CRM.post, otherwise it was Kernel.post if it didn’t have any Module name attached.

Is there some way to find out where a function comes from by hovering over the function name or something?
Because even now when I went to the test/support/conn_case.ex it have two more use lines as use ExUnit.CaseTemplate and use Phoenix.ConnTest, so if one wants to know where some function comes from, s/he will need to look in all the files. :frowning:

Is there some way to find out where a function comes from by hovering over the function name or something?

Probably, I’ve never seen/used it. You might check out if alchemist does it, since it has code definition lookup which is close to what you want, I think …

I think it’s usually pretty easy to guess where a function comes from. For example, in your case it probably comes from somewhere that has “conn” or “phoenix” or “plug” in its name, rather than “ExUnit.CaseTemplate”. And test macro probably comes from ExUnit.CaseTemplate rather than Phoenix.ConnTest.

Also, I generally avoid heavy use of import and use in my own code, which might be the reason I don’t have problems finding functions.

1 Like

Thank You for the link and the explanation!
The Alchemist’s website says that the power is for Emacs users. Can I somehow make it work inside VSCode?
and Is learning Emacs easy for someone who already knows basics of VIM ?

There’s JakeBecker/vscode-elixir-ls for vscode. It seems to be using something similar to alchemist-server.

1 Like