运行测试时Plug.Router.InvalidSpecError

时间:2018-02-21 03:26:55

标签: elixir phoenix-framework

我正在通过Phoenix for Rails Developers工作,我在测试时遇到了问题。当我运行mix test时,收到以下错误:

== Compilation error in file lib/storex_web/router.ex ==
   ** (Plug.Router.InvalidSpecError) :identifier in routes must be made of letters, numbers and underscores
    (plug) lib/plug/router/utils.ex:193: Plug.Router.Utils.binary_to_identifier/2
    (plug) lib/plug/router/utils.ex:156: Plug.Router.Utils.segment_match/3
    (plug) lib/plug/router/utils.ex:120: Plug.Router.Utils.build_path_match/4
    (phoenix) lib/phoenix/router/route.ex:65: Phoenix.Router.Route.build_path_and_binding/1
    (phoenix) lib/phoenix/router/route.ex:50: Phoenix.Router.Route.exprs/1
    (phoenix) lib/phoenix/router.ex:320: anonymous fn/1 in Phoenix.Router."MACRO-__before_compile__"/2
    (elixir) lib/enum.ex:1294: Enum."-map/2-lists^map/1-0-"/2
    (elixir) lib/enum.ex:1294: Enum."-map/2-lists^map/1-0-"/2

router.ex文件的相关部分如下所示:

  scope "/", StorexWeb do
    pipe_through :browser # Use the default browser stack

    get "/", BookController, :index
    get "/books/:id", BookController, :show

    resources "/carts", CartController, singleton: true, only: [:show, :create, :delete]
  end

我知道错误来自/books/:id行,因为mix test在我注释掉该行时不会抛出错误。路线似乎设置正确,因为当我运行mix phx.server时,我可以毫无问题地访问该路线。我做错了什么?

0 个答案:

没有答案