script
February 21, 2018, 8:23am
1
I am writing a very small test for index controller action like this:
test "index/2 shows all the records" do
conn = get build_conn(), api_v1_action_path(build_conn(), :index)
assert json_response(build_conn(), 200)
end
When I run the test it gives this error:
** (ArgumentError) argument error
code: conn = get build_conn(), api_v1_action_path(build_conn(), :index)
stacktrace:
:erlang.apply("/s", :init, [])
Any possible solutions?
Thanks
idi527
February 21, 2018, 8:44am
2
Sorry for being off-topic, but why are you building conn
three times?
Why not
test "index/2 shows all the records" do
conn = build_conn()
conn = get(conn, api_v1_action_path(conn, :index))
assert json_response(conn, 200)
end
otherwise assert json_response(build_conn(), 200)
is meaningless.
script
February 21, 2018, 8:47am
3
build_conn
|> get(api_v1_action_path(build_conn(), :index))
|> json_response(200)
How about his?
idi527
February 21, 2018, 8:56am
4
Why not use conn
for api_v1_action_path/2
as well?
script
February 21, 2018, 8:57am
5
yes tried that too. same result.
idi527
February 21, 2018, 9:09am
6
Is this the whole stacktrace?
Which function causes the error? You can separate function calls to happen on separate lines to find that out.
Does the error happen if you hardcode the path?
script
February 21, 2018, 9:17am
7
** (ArgumentError) argument error
code: |> get(api_v1_entity_path(build_conn(), :index))
stacktrace:
:erlang.apply("/s", :init, [])
(phoenix) lib/phoenix/test/conn_test.ex:236: Phoenix.ConnTest.dispatch_endpoint/5
(phoenix) lib/phoenix/test/conn_test.ex:224: Phoenix.ConnTest.dispatch/5
This is the complete stacktrace.
Error is on this ;
|> get(api_v1_entity_path(build_conn(), :index))
idi527
February 21, 2018, 9:25am
8
Error is on this ;
get
or api_v1_entity_path
? What does api_v1_entity_path
return?
For some reason endpoint
becomes "/s"
in your case. See phoenix/lib/phoenix/test/conn_test.ex at v1.3 · phoenixframework/phoenix · GitHub
Do you have @endpoint
module attribute set?