Popularity
8.8
Declining
Activity
0.0
Stable
71
11
9

Monthly Downloads: 12
Programming language: Haskell
License: ISC License
Tags: Testing    
Latest version: v0.2.0.0

monad-mock alternatives and similar packages

Based on the "Testing" category.
Alternatively, view monad-mock alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of monad-mock or a related project?

Add another 'Testing' Package

README

monad-mock Build Status

monad-mock is a Haskell package that provides a monad transformer to help create “mocks” of mtl-style typeclasses, intended for use in unit tests. A mock can be executed by providing a sequence of expected monadic calls and their results, and the mock will verify that the computation conforms to the expectation.

For example, imagine a MonadFileSystem typeclass, which describes a class of monads that may perform filesystem operations:

class Monad m => MonadFileSystem m where
  readFile :: FilePath -> m String
  writeFile :: FilePath -> String -> m ()

Using MockT, it’s possible to test computations that use MonadFileSystem in a completely pure way:

copyFile :: MonadFileSystem m => FilePath -> FilePath -> m ()
copyFile a b = do
  x <- readFile a
  writeFile b x

makeMock "FileSystemAction" [ts| MonadFileSystem |]

spec = describe "copyFile" $
  it "reads a file and writes its contents to another file" $
    evaluate $ copyFile "foo.txt" "bar.txt"
      & runMock [ ReadFile "foo.txt" :-> "contents"
                , WriteFile "bar.txt" "contents" :-> () ]

For more information, see the documentation on Hackage.