Returning to a passing test suite

We also have a few random test failures that we'll want to correct very quickly before we close out this chapter. The first is a result of us adding new preloads:

  1) test polls show_poll/1 returns a specific poll (Vocial.VotesTest)
test/vocial/votes/votes_test.exs:62
Assertion with == failed
code: assert Votes.get_poll(poll.id()) == poll
left: %Vocial.Votes.Poll{__meta__: #Ecto.Schema.Metadata<:loaded, "polls">, id: 84, image: nil, inserted_at: ~N[2018-02-06 16:33:20.390976], options: [], title: "Hello", updated_at: ~N[2018-02-06 16:33:20.390987], user: #Ecto.Association.NotLoaded<association :user is not loaded>, user_id: 131, vote_records: [], messages: []}
right: %Vocial.Votes.Poll{__meta__: #Ecto.Schema.Metadata<:loaded, "polls">, id: 84, image: nil, inserted_at: ~N[2018-02-06 16:33:20.390976], options: [], title: "Hello", updated_at: ~N[2018-02-06 16:33:20.390987], user: #Ecto.Association.NotLoaded<association :user is not loaded>, user_id: 131, vote_records: [], messages: #Ecto.Association.NotLoaded<association :messages is not loaded>}
stacktrace:
test/vocial/votes/votes_test.exs:64: (test)

The good news is that this one is very easy for us to fix. In our poll_fixture/1 function in test/vocial/votes/votes_text.exs, just change the line in the with statement that adds the preloads to:

poll <- Repo.preload(poll, [:options, :image, :vote_records, :messages]) do

This leaves us with one failing test on page controller, which is happening since we ripped out the boilerplate code but left the test in place. The failing test is:

  1) test GET / (VocialWeb.PageControllerTest)
test/vocial_web/controllers/page_controller_test.exs:4
Assertion with =~ failed
code: assert html_response(conn, 200) =~ "Welcome to Phoenix!"

Open up test/vocial_web/controllers/page_controller_test.exs and change the failing test to this instead:

  test "GET /", %{conn: conn} do
conn = get(conn, "/")
assert html_response(conn, 200)
end

Now everything is back to green and fully-passing tests!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset