Hi *, I’m done with my first library in Elixir, a simple HTTP client to authenticate against some internal services my company has.
I would like to document it maybe by publishing everything on Github pages.
I would also like to use doctests as much as possible, as I think they’re a wonderful idea.
My only question is: should I mock the HTTP calls? Mock a server? What is the preferred way of writing doctests for this kind of libraries?
I’m looking at HTTPoison and it has no doctests, so maybe it’s not such a great idea?
Thanks in advance
I believe doctests are best suited for testing pure functions. It’s hard to test functions with side effects (like http calls) since they require a lot of setup that can’t be easily expressed in the short form of a doctest. Usually though, there’s a lot of helper functions that are pure and can be easily tested, beside the http calls themselves.
Agree with @michalmuskala, Doctests Should not be tested using complex setups. Only functionally way to represent how your function works
I see, thank you very much for the insight. One question though: aren’t helper functions normally private, especially if they’re only helper functions?