RPG Character Sheet > Unit Test #6 "ask_level/0 it prints a prompt" failing

All other unit tests pass.

This one fails because the expectation is to see only the prompt, when it reality, it sees the prompt and the input it types.

Code Run

io= capture_io("1\n", fn > RPG.CharacterSheet.ask_level() end)
assert io == "What is your character's level?\n"

TEST FAILURE

test ask_level/O it prints a prompt (RPG. CharacterSheetTest)
test/rpg/character_sheet_test.exs:49
Assertion with == failed
code:   assert io == "What is your character's level?\n" 
left:   "What is your character's level?\n\"1\\n\"\n" 
right:  "What is your character's level?\n" 
stacktrace:
   test/rpg/character_sheet_test.exs:52: (test)

Surely this is a bug in the test case? It should either include the expectation of what it types or test only the leftmost characters in the string.

So… how did you solve ask_level?

1 Like

Thanks. That solved it :smiley:

I was about to copy and paste the code while thinking, “it’s just the IO.gets” that’s causing the issue. Then I noticed I had an IO.inspect left there from trying to debug another issue (I was getting an :eof).

All works now.

1 Like