gjaldon/ecto_enum

how to test and pass coverage?

silva96 opened this issue · 1 comments

I have the following ecto_enums.ex file

import EctoEnum
defenum PostStatusEnum, :post_status, [:importing, :imported]
defmodule MyApp.EctoEnumsTest do
  use MyApp.DataCase

  describe "PostStatusEnum" do
    alias MyApp.MyContext.Post

    test "raises when input is not in the enum map" do
      error = {:status, {"is invalid", [type: PostStatusEnum, validation: :cast]}}
      changeset = Ecto.Changeset.cast(%Post{}, %{"status" => "a_not_valid_status"}, [:status])
      assert error in changeset.errors
    end

    test "doesn't raise when input is in the enum map" do
      changeset = Ecto.Changeset.cast(%Post{}, %{"status" => "importing"}, [:status])
      assert length(changeset.errors) == 0
      changeset = Ecto.Changeset.cast(%Post{}, %{"status" => :importing}, [:status])
      assert length(changeset.errors) == 0
    end
  end
end

Tests pass, im happy with that. But coverage reporting tool is showing 0% for ecto_enums.ex

Finished in 1.8 seconds
21 tests, 0 failures

Randomized with seed 18593
----------------
COV    FILE                                        LINES RELEVANT   MISSED
  0.0% lib/my_app/ecto_enums.ex                    2        1        1

How can I make coverage tool put a 100% in my ecto_enums.ex ?

Auto responding myself

test "it has the correct map values" do
    assert PostStatusEnum.__enum_map__() == [importing: :importing, imported: :imported]
end