未定义函数 put_req_header/3

Mat*_*ski 1 elixir phoenix-framework

我在 Phoenix 应用程序中有以下模块。此代码基本上是共享规范示例。它看起来像这样:

defmodule TattooBackend.CurrentPasswordRequiredTest do
  @moduledoc """
  This module defines tests that are testing api current password requirement.
  """
  import Phoenix.ConnTest

  alias TattooBackend.Web.Router

  defmacro test_current_password_required_for(method, path_name, action) do
    quote do
      test "without current password", %{conn: conn} do
        method    = unquote(method)
        path_name = unquote(path_name)
        action    = unquote(action)
        account = insert(:account)

        assert make_unauthenticated_request(conn, @endpoint, method, path_name, action, account) == %{
          "error" => "B??dne has?o."
        }
      end
    end
  end

  def make_unauthenticated_request(conn, endpoint, method, path_name, action, account) do
    path = apply(Router.Helpers, path_name, [conn, action])

    conn
    |> put_req_header("authorization", "#{token(account)}")
    |> dispatch(endpoint, method, path, nil)
    |> json_response(422)
  end
end
Run Code Online (Sandbox Code Playgroud)

当我运行我的规范时,它返回错误:

** (CompileError) test/support/shared_tests/current_password_required.ex:28: undefined function put_req_header/3
Run Code Online (Sandbox Code Playgroud)

我该如何解决?

mic*_*ala 7

该功能实际上是Plug.Conn.put_req_header/3- 您需要使用全名或导入Plug.Conn模块。