From fb83d5539a078ae14574fcad0c34dd364db28630 Mon Sep 17 00:00:00 2001 From: Mike Zornek Date: Tue, 16 Jul 2024 20:59:48 -0400 Subject: [PATCH] chore: add `tiny_maps` to help with condensed test syntax (#16) --- mix.exs | 3 +++ mix.lock | 1 + test/flick/votes_test.exs | 12 +++--------- test/flick_web/live/ballots/editor_live_test.exs | 2 +- test/flick_web/live/ballots/index_live_test.exs | 2 +- test/flick_web/live/ballots/viewer_live_test.exs | 4 ++-- test/support/conn_case.ex | 1 + test/support/data_case.ex | 1 + 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/mix.exs b/mix.exs index 688ff7f..aeb14cf 100644 --- a/mix.exs +++ b/mix.exs @@ -35,6 +35,9 @@ defmodule Flick.MixProject do # For test-driven development. {:mix_test_watch, "~> 1.0", only: [:dev, :test], runtime: false}, + # To allow our test descriptions to use a condensed map syntax. + {:tiny_maps, "~> 3.0"}, + # Unorganized {:bandit, "~> 1.2"}, {:dns_cluster, "~> 0.1.1"}, diff --git a/mix.lock b/mix.lock index bdef756..6b798ad 100644 --- a/mix.lock +++ b/mix.lock @@ -37,6 +37,7 @@ "telemetry_metrics": {:hex, :telemetry_metrics, "0.6.2", "2caabe9344ec17eafe5403304771c3539f3b6e2f7fb6a6f602558c825d0d0bfb", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "9b43db0dc33863930b9ef9d27137e78974756f5f198cae18409970ed6fa5b561"}, "telemetry_poller": {:hex, :telemetry_poller, "1.0.0", "db91bb424e07f2bb6e73926fcafbfcbcb295f0193e0a00e825e589a0a47e8453", [:rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b3a24eafd66c3f42da30fc3ca7dda1e9d546c12250a2d60d7b81d264fbec4f6e"}, "thousand_island": {:hex, :thousand_island, "1.3.5", "6022b6338f1635b3d32406ff98d68b843ba73b3aa95cfc27154223244f3a6ca5", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "2be6954916fdfe4756af3239fb6b6d75d0b8063b5df03ba76fd8a4c87849e180"}, + "tiny_maps": {:hex, :tiny_maps, "3.0.0", "afe01a2aa19bd0e8fc5b856529792205e90448caa1d96d934bb0ab5bddfeba49", [:mix], [], "hexpm", "29246bb7fa7a96ced99cf1761d0e51b96b12d0eead1f0fb0e245919e70a6bd6a"}, "websock": {:hex, :websock, "0.5.3", "2f69a6ebe810328555b6fe5c831a851f485e303a7c8ce6c5f675abeb20ebdadc", [:mix], [], "hexpm", "6105453d7fac22c712ad66fab1d45abdf049868f253cf719b625151460b8b453"}, "websock_adapter": {:hex, :websock_adapter, "0.5.6", "0437fe56e093fd4ac422de33bf8fc89f7bc1416a3f2d732d8b2c8fd54792fe60", [:mix], [{:bandit, ">= 0.6.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "e04378d26b0af627817ae84c92083b7e97aca3121196679b73c73b99d0d133ea"}, } diff --git a/test/flick/votes_test.exs b/test/flick/votes_test.exs index 4bdc21f..ed8c18b 100644 --- a/test/flick/votes_test.exs +++ b/test/flick/votes_test.exs @@ -19,9 +19,7 @@ defmodule Flick.VotesTest do {:ok, published_ballot: ballot} end - test "success: creates a vote recording the passed in answers", %{ - published_ballot: published_ballot - } do + test "success: creates a vote recording the passed in answers", ~M{published_ballot} do published_ballot_id = published_ballot.id assert {:ok, vote} = @@ -45,9 +43,7 @@ defmodule Flick.VotesTest do } = vote end - test "success: a vote does not need to rank every possible answer", %{ - published_ballot: published_ballot - } do + test "success: a vote does not need to rank every possible answer", ~M{published_ballot} do published_ballot_id = published_ballot.id assert {:ok, vote} = @@ -110,9 +106,7 @@ defmodule Flick.VotesTest do assert "answers must not be duplicated" in errors_on(pizza_2).value end - test "failure: a vote needs to include at least one ranked answer", %{ - published_ballot: published_ballot - } do + test "failure: a vote needs to include at least one ranked answer", ~M{published_ballot} do attrs = %{ "ranked_answers" => [ %{"value" => ""}, diff --git a/test/flick_web/live/ballots/editor_live_test.exs b/test/flick_web/live/ballots/editor_live_test.exs index f1dab65..95362b8 100644 --- a/test/flick_web/live/ballots/editor_live_test.exs +++ b/test/flick_web/live/ballots/editor_live_test.exs @@ -1,7 +1,7 @@ defmodule FlickWeb.Ballots.EditorLiveTest do use FlickWeb.ConnCase, async: true - test "renders create ballot form", %{conn: conn} do + test "renders create ballot form", ~M{conn} do assert {:ok, view, _html} = live(conn, ~p"/ballots/new") assert has_element?(view, "#ballot_question_title") assert has_element?(view, "#ballot_possible_answers") diff --git a/test/flick_web/live/ballots/index_live_test.exs b/test/flick_web/live/ballots/index_live_test.exs index 87df5b8..04bb89d 100644 --- a/test/flick_web/live/ballots/index_live_test.exs +++ b/test/flick_web/live/ballots/index_live_test.exs @@ -1,7 +1,7 @@ defmodule FlickWeb.Ballots.IndexLiveTest do use FlickWeb.ConnCase, async: true - test "renders list of ballots", %{conn: conn} do + test "renders list of ballots", ~M{conn} do ballots = Enum.map(1..3, fn _ -> ballot_fixture() end) assert {:ok, view, _html} = live(conn, ~p"/ballots") assert has_element?(view, "table#ballots") diff --git a/test/flick_web/live/ballots/viewer_live_test.exs b/test/flick_web/live/ballots/viewer_live_test.exs index 1b548e4..f628c40 100644 --- a/test/flick_web/live/ballots/viewer_live_test.exs +++ b/test/flick_web/live/ballots/viewer_live_test.exs @@ -1,13 +1,13 @@ defmodule FlickWeb.Ballots.ViewerLiveTest do use FlickWeb.ConnCase, async: true - test "renders ballot details", %{conn: conn} do + test "renders ballot details", ~M{conn} do ballot = ballot_fixture() assert {:ok, view, _html} = live(conn, ~p"/ballots/#{ballot}") assert has_element?(view, "#ballot-question-title", ballot.question_title) end - test "responds with 404 when no ballot is found", %{conn: conn} do + test "responds with 404 when no ballot is found", ~M{conn} do assert_raise Ecto.NoResultsError, fn -> live(conn, ~p"/ballots/#{Ecto.UUID.generate()}") end diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index 51ec016..4acd3c0 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -29,6 +29,7 @@ defmodule FlickWeb.ConnCase do import Phoenix.ConnTest import FlickWeb.ConnCase import Phoenix.LiveViewTest + import TinyMaps import Support.Fixtures.BallotFixture end diff --git a/test/support/data_case.ex b/test/support/data_case.ex index 3f0a3d8..b65d762 100644 --- a/test/support/data_case.ex +++ b/test/support/data_case.ex @@ -24,6 +24,7 @@ defmodule Flick.DataCase do import Ecto.Changeset import Ecto.Query import Flick.DataCase + import TinyMaps import Support.Fixtures.BallotFixture end