DockYard-Academy / curriculum

MIT License
975 stars 249 forks source link

Doctest failed to read the error on RPG dialogue exercise #805

Closed EnjoyneeringDev closed 1 year ago

EnjoyneeringDev commented 1 year ago

Describe the issue The doctest should be able to catch the error because we don't specify the name on Character struct, but it's failed to do so, hence the doctest is failed. Actually it's because of doctest won't be able to read compilation error in the first place (ref)

Reproduction Steps (If Applicable) Steps to reproduce the behavior:

  1. Go to RPG dialogue exercise
  2. Solve the problem
  3. Run the code (it's a compilation error, not runtime error, hence it's failed)

Expected behavior 12 test passed (all green)

Please see the #bug here comment on code below

Screenshots

defmodule Character do
  @moduledoc """
  Character

  Defines a character struct, and functions for creating character dialogue.

  iex> %Character{name: "Frodo"}
  %Character{name: "Frodo", weapon: nil, class: nil}

  The :name key is required.

  # bug here
  iex> %Character{}
  ** (ArgumentError) the following keys must also be given when building struct Character: [:name]
  # bug here
  """
  @enforce_keys [:name]
  defstruct @enforce_keys ++ [:class, :weapon]

  @doc """
  Introduce the character by name.

  ## Examples

    iex> Character.introduce(%Character{name: "Gimli"})
    "My name is Gimli."

    iex> Character.introduce(%Character{name: "Aragorn"})
    "My name is Aragorn."
  """
  def introduce(%Character{} = character) do
    "My name is #{character.name}."
  end

  @doc """
  Declare a character attack.

  ## Examples

    iex> Character.attack(%Character{name: "Gimli", weapon: "axe"})
    "I attack with my axe!"

    iex> Character.attack(%Character{name: "Aragorn", weapon: "sword"})
    "I attack with my sword!"
  """
  def attack(%Character{} = character) do
    "I attack with my #{if character.weapon == nil do
      "weapon"
    else
      character.weapon
    end}!"
  end

  @doc """
  Declare a character's class.

  ## Examples

    iex> Character.class(%Character{name: "Gimli", class: "warrior"})
    "I am a warrior."

    iex> Character.class(%Character{name: "Aragorn", class: "ranger"})
    "I am a ranger."
  """
  def class(%Character{} = character) do
    "I am a #{character.class}."
  end

  @doc """
  Declare a character's name and class in a war cry.

  ## Examples

    iex> Character.war_cry(%Character{name: "Gimli", class: "warrior"})
    "My name is Gimli and I am a warrior!"

    iex> Character.war_cry(%Character{name: "Aragorn", class: "ranger"})
    "My name is Aragorn and I am a ranger!"
  """
  def war_cry(%Character{} = character) do
    "My name is #{character.name} and I am a #{character.class}!"
  end

  @doc """
  Declare that one character has defeated another.

  ## Examples

    iex> Character.defeat(%Character{name: "Gimli"}, %Character{name: "Aragorn", class: "ranger"})
    "My name is Gimli and I have defeated the ranger Aragorn!"

    iex> Character.defeat(%Character{name: "Aragorn"}, %Character{name: "Gimli", class: "warrior"})
    "My name is Aragorn and I have defeated the warrior Gimli!"
  """
  def defeat(%Character{} = character1, %Character{} = character2) do
    "My name is #{character1.name} and I have defeated the #{character2.class} #{character2.name}!"
  end
end
BrooklinJazz commented 1 year ago

@amir-repository can you make sure you are running the latest version of the curriculum?

It looks like this issue has already been resolved.