I'm following a book "Programming Phoenix >= 1.4", got stuck at "Testing Logged-Out Users" (Integration Tests, page 161). Test fail.
video_controller_test.exs
defmodule RumblWeb.VideoControllerTest do
use RumblWeb.ConnCase, async: true
test "requires user authentication on all actions", %{conn: conn} do
Enum.each([
get(conn, Routes.video_path(conn, :new)),
get(conn, Routes.video_path(conn, :index)),
get(conn, Routes.video_path(conn, :show, "123")),
get(conn, Routes.video_path(conn, :edit, "123")),
put(conn, Routes.video_path(conn, :update, "123", %{})),
post(conn, Routes.video_path(conn, :create, %{})),
delete(conn, Routes.video_path(conn, :delete, "123")),
], fn conn ->
assert html_response(conn, 302)
assert conn.halted
end)
end
end
mix test test/rumbl_web
1) test requires user authentication on all actions (RumblWeb.VideoControllerTest)
test/rumbl_web/controllers/video_controller_test.exs:4
** (FunctionClauseError) no function clause matching in Rumbl.Multimedia.list_user_videos/1
The following arguments were given to Rumbl.Multimedia.list_user_videos/1:
# 1
nil
Attempted function clauses (showing 1 out of 1):
def list_user_videos(%Rumbl.Accounts.User{} = user)
code: get(conn, Routes.video_path(conn, :index)),
stacktrace:
(rumbl) lib/rumbl/multimedia.ex:107: Rumbl.Multimedia.list_user_videos/1
(rumbl) lib/rumbl_web/controllers/video_controller.ex:18: RumblWeb.VideoController.index/3
(rumbl) lib/rumbl_web/controllers/video_controller.ex:1: RumblWeb.VideoController.action/2
(rumbl) lib/rumbl_web/controllers/video_controller.ex:1: RumblWeb.VideoController.phoenix_controller_pipeline/2
(phoenix) lib/phoenix/router.ex:352: Phoenix.Router.__call__/2
(rumbl) lib/rumbl_web/endpoint.ex:1: RumblWeb.Endpoint.plug_builder_call/2
(rumbl) lib/rumbl_web/endpoint.ex:1: RumblWeb.Endpoint.call/2
(phoenix) lib/phoenix/test/conn_test.ex:225: Phoenix.ConnTest.dispatch/5
test/rumbl_web/controllers/video_controller_test.exs:7: (test)
Finished in 0.2 seconds
4 tests, 1 failure
My repo: https://github.com/zervis/rumbl
question from:
https://stackoverflow.com/questions/65645162/following-a-book-programming-phoenix-1-4-got-stuck-at-testing-logged-out 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…