defmodule Dog do
def guard_house(woof) do
case woof do
"woof" -> bark(1)
"woof woof" -> bark(2)
"woof woof woof" -> bark(3)
_ -> bark(0)
defp bark(times) do
for i <- 0..times, do: outside_api("woof")
Is there a way to check the attributes that bark is receiving?
I don’t want to make it public just for the test to pass
The output is a call to external api, so I don’t have how to check the result of it…
My strong recommendation is not to test private functions or make them public only to test them. It is actually possible to over test. Add tests for the happy path of your public function, sure, and maybe some edge cases if they are critical, or complicated enough that tests will help give you confidence they have been implemented correctly (certainly write a test rather than test things manually). Whether or not a function is private should be between you and your public function, no one else should know, including the tests. Don’t end up having to rewrite tests just because you refactored the internal implementation of a function without changing its spec.