-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CLI command
characters show
to show a saved character
Of note, we had to duplicate some helper functions from `characters_test.exs` to `custom_parsers_test.exs`. It'd be desirable if these could be shared utility methods that multiple tests can use. However to do so we either need to include the test helper functions in the package libary code _or_ create some test macros. The former is undersireable as I don't believe testing helpers should generally be distributed as part of the library. The latter is more technical than we need at this point in time. Sometime in the future we are likely to move to the latter option.
- Loading branch information
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,53 @@ | ||
defmodule ExTTRPGDevTest.CLI.CustomParsers do | ||
use ExUnit.Case | ||
|
||
alias ExTTRPGDev.Characters | ||
alias ExTTRPGDev.Characters.Character | ||
alias ExTTRPGDev.CLI.CustomParsers | ||
alias ExTTRPGDev.RuleSystems | ||
alias ExTTRPGDev.RuleSystems.RuleSystem | ||
|
||
doctest ExTTRPGDev.CLI.CustomParsers, | ||
except: [ | ||
system_parser: 1 | ||
] | ||
|
||
def build_test_character do | ||
RuleSystems.list_systems() | ||
|> List.first() | ||
|> RuleSystems.load_system!() | ||
|> Character.gen_character!() | ||
end | ||
|
||
def save_test_character do | ||
character = build_test_character() | ||
Characters.save_character!(character) | ||
character | ||
end | ||
|
||
def delete_test_character(%Character{} = character) do | ||
File.rm(Characters.character_file_path!(character)) | ||
end | ||
|
||
def system_parser_test do | ||
# If no error was raised, then all is good | ||
{:ok, %RuleSystem{}} = CustomParsers.system_parser("dnd_5e_srd") | ||
|
||
# Should raise an error | ||
assert_raise RuntimeError, CustomParsers.system_parser("unknown_system") | ||
end | ||
|
||
def character_parser_test do | ||
character = save_test_character() | ||
|
||
{:ok, %Character{}} = CustomParsers.character_parser(character.metadata.slug) | ||
|
||
# cleanup | ||
delete_test_character(character) | ||
|
||
# should raise an error | ||
assert_raise RuntimeError, CustomParsers.character_parser(character.metadata.slug) | ||
|
||
assert False | ||
end | ||
end |