首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Phoenix: Mix phoenix.gen.html生成失败的测试

Phoenix: Mix phoenix.gen.html生成失败的测试
EN

Stack Overflow用户
提问于 2017-04-13 18:42:16
回答 1查看 196关注 0票数 0

我先运行mix phoenix.gen.html Topic topics title used:boolean,然后运行mix ecto.migrate来运行迁移。

我将此添加到我的路由中

代码语言:javascript
复制
defmodule ParrotApi.Router do
  use ParrotApi.Web, :router

  pipeline :browser do
    plug :accepts, ["html"]
    plug :fetch_session
    plug :fetch_flash
    plug :protect_from_forgery
    plug :put_secure_browser_headers
  end

  pipeline :api do
    plug :accepts, ["json"]
  end

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

    resources "/topics", TopicController #<-----------------------------
    get "/", CallController, :index
  end
end

在那之后,我运行了主题控制器的测试,其中一些失败了:

代码语言:javascript
复制
➜  parrot-api git:(master) ✗ mix test test/controllers/topic_controller_test.exs:13
Including tags: [line: "13"]
Excluding tags: [:test]



  1) test renders form for new resources (ParrotApi.TopicControllerTest)
     test/controllers/topic_controller_test.exs:13
     ** (Phoenix.Template.UndefinedError) Could not render "app.html" for ParrotApi.LayoutView, please define a matching clause for render/2 or define a template at "web/templates/layout". No templates were compiled for this module.
     Assigns:

     %{changeset: #Ecto.Changeset<action: nil, changes: %{}, errors: [title: {"can't be blank", [validation: :required]}], data: #ParrotApi.Topic<>, valid?: false>, conn: %Plug.Conn{adapter: {Plug.Adapters.Test.Conn, :...}, assigns: %{changeset: #Ecto.Changeset<action: nil, changes: %{}, errors: [title: {"can't be blank", [validation: :required]}], data: #ParrotApi.Topic<>, valid?: false>, layout: {ParrotApi.LayoutView, "app.html"}}, before_send: [#Function<0.101282891/1 in Plug.CSRFProtection.call/2>, #Function<4.39648223/1 in Phoenix.Controller.fetch_flash/2>, #Function<0.131660147/1 in Plug.Session.before_send/2>, #Function<1.120807292/1 in Plug.Logger.call/2>], body_params: %{}, cookies: %{}, halted: false, host: "www.example.com", method: "GET", owner: #PID<0.330.0>, params: %{}, path_info: ["topics", "new"], path_params: %{}, peer: {{127, 0, 0, 1}, 111317}, port: 80, private: %{ParrotApi.Router => {[], %{}}, :phoenix_action => :new, :phoenix_controller => ParrotApi.TopicController, :phoenix_endpoint => ParrotApi.Endpoint, :phoenix_flash => %{}, :phoenix_format => "html", :phoenix_layout => {ParrotApi.LayoutView, :app}, :phoenix_pipelines => [:browser], :phoenix_recycled => true, :phoenix_route => #Function<9.45870687/1 in ParrotApi.Router.match_route/4>, :phoenix_router => ParrotApi.Router, :phoenix_template => "new.html", :phoenix_view => ParrotApi.TopicView, :plug_session => %{}, :plug_session_fetch => :done, :plug_skip_csrf_protection => true}, query_params: %{}, query_string: "", remote_ip: {127, 0, 0, 1}, req_cookies: %{}, req_headers: [], request_path: "/topics/new", resp_body: nil, resp_cookies: %{}, resp_headers: [{"cache-control", "max-age=0, private, must-revalidate"}, {"x-request-id", "4885goamao9jhvne2upmbjdmd56iqfdu"}, {"x-frame-options", "SAMEORIGIN"}, {"x-xss-protection", "1; mode=block"}, {"x-content-type-options", "nosniff"}], scheme: :http, script_name: [], secret_key_base: "JzeH+GcCE+1xgWtHDgHyG8YyZAU5WCcT2GJGLjdpXKbXfsdJF3YnJNYhc7llI75r", state: :unset, status: nil}, template_not_found: ParrotApi.LayoutView, view_module: ParrotApi.TopicView, view_template: "new.html"}

     stacktrace:
       (phoenix) lib/phoenix/template.ex:364: Phoenix.Template.raise_template_not_found/3
       (phoenix) lib/phoenix/view.ex:335: Phoenix.View.render_to_iodata/3
       (phoenix) lib/phoenix/controller.ex:646: Phoenix.Controller.do_render/4
       (parrot_api) web/controllers/topic_controller.ex:1: ParrotApi.TopicController.action/2
       (parrot_api) web/controllers/topic_controller.ex:1: ParrotApi.TopicController.phoenix_controller_pipeline/2
       (parrot_api) lib/parrot_api/endpoint.ex:1: ParrotApi.Endpoint.instrument/4
       (parrot_api) lib/phoenix/router.ex:261: ParrotApi.Router.dispatch/2
       (parrot_api) web/router.ex:1: ParrotApi.Router.do_call/2
       (parrot_api) lib/parrot_api/endpoint.ex:1: ParrotApi.Endpoint.phoenix_pipeline/1
       (parrot_api) lib/parrot_api/endpoint.ex:1: ParrotApi.Endpoint.call/2
       (phoenix) lib/phoenix/test/conn_test.ex:224: Phoenix.ConnTest.dispatch/5
       test/controllers/topic_controller_test.exs:14: (test)



Finished in 0.1 seconds
10 tests, 1 failure, 9 skipped

以下是我的依赖项列表:

代码语言:javascript
复制
 defp deps do
   [
     {:phoenix, "~> 1.2.1"},
     {:phoenix_pubsub, "~> 1.0"},
     {:phoenix_ecto, "~> 3.0"},
     {:phoenix_slime, "~> 0.8.0"},
     {:postgrex, ">= 0.0.0"},
     {:phoenix_html, "~> 2.6"},
     {:phoenix_live_reload, "~> 1.0", only: :dev},
     {:gettext, "~> 0.11"},
     {:cowboy, "~> 1.0"},
     {:poison, "~> 2.0"},
     {:timex, "~> 3.0"},
  ]

这是怎么回事?

EN

回答 1

Stack Overflow用户

发布于 2017-04-13 18:51:23

我不得不将以下代码添加到我的test.exs文件中:

代码语言:javascript
复制
config :phoenix, :template_engines,
 slim: PhoenixSlime.Engine,
 slime: PhoenixSlime.Engine
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43390100

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档