antonmi / espec_phoenix

ESpec for Phoenix web framework.
MIT License
137 stars 33 forks source link

Controller Test Render Issue #14

Closed baoist closed 8 years ago

baoist commented 8 years ago

Switched from rendering via render conn, "show.html", user: conn.assigns.current_user to render conn, :show, user: conn.assigns.current_user and I receive the following error in a controller test.

** (UndefinedFunctionError) undefined function: Plug.Conn.Unfetched.fetch/2
    (plug) Plug.Conn.Unfetched.fetch(%Plug.Conn.Unfetched{aspect: :params}, "_format")
    (elixir) lib/access.ex:72: Access.get/3
    (phoenix) lib/phoenix/controller.ex:592: Phoenix.Controller.render/3
    (stdlib) erl_eval.erl:669: :erl_eval.do_apply/6
    (elixir) src/elixir.erl:196: :elixir.erl_eval/3
    (elixir) src/elixir.erl:184: :elixir.eval_forms/4
    (elixir) lib/code.ex:194: Code.eval_quoted/3
    spec/controllers/student/profile_controller_spec.exs:28: Project.ProfileControllerSpec.subject/0
baoist commented 8 years ago

As a workaround I was able to pass in my own conn to action, similar to:

subject action :show, %{}, conn |> Phoenix.Controller.accepts(["html", "json"])
fredwu commented 8 years ago

Ran into the same issue in a controller spec that asserts using render_template. The workaround works (thanks @baoist!).

    ** (UndefinedFunctionError) function Plug.Conn.Unfetched.fetch/2 is undefined (Plug.Conn.Unfetched does not implement the Access behaviour)
    (plug) Plug.Conn.Unfetched.fetch(%Plug.Conn.Unfetched{aspect: :params}, "_format")
    (elixir) lib/access.ex:148: Access.fetch/2
    (elixir) lib/access.ex:179: Access.get/3
    (phoenix) lib/phoenix/controller.ex:589: Phoenix.Controller.render/3
    (espec) lib/espec/let/let_impl.ex:9: ESpec.Let.Impl.let_eval/2
    spec/controllers/admin/user_controller_spec.exs:2: Persumi.Admin.UserControllerSpec.should/1
    (espec) lib/espec/example_runner.ex:62: ESpec.ExampleRunner.try_run/3
    (espec) lib/espec/example_runner.ex:39: ESpec.ExampleRunner.run_example/2
antonmi commented 8 years ago

Hi, guys! Please, migrate to v0.5.0