I have found other questions on similar lines but nothing that answers my question in this particular scenario. Furthermore, there seem to be few resources which succinctly cover the subject of unit testing IO actions in Haskell.
Let's say I have this typeclass for my database communication:
data Something = Something String deriving Show
class MonadIO m => MonadDB m where
getSomething :: String -> m Something
getSomething s = do
... -- assume a DB call is made and an otherwise valid function
instance MonadDB IO
and this function which uses it:
getIt :: MonadDB m => m (Int, Something)
getIt = do
s@(Something str) <- getSomething "hi"
return (length str, s) -- excuse the contrived example
I wish to test this getIt
function with hspec but without it talking to the database, which presumably means replacing which MonadDB
it uses, but how do I achieve that?