monad-mock: A monad transformer for mocking mtl-style typeclasses

[ library, testing ] [ Propose Tags ]

This package provides a monad transformer that helps 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 more information, see the module documentation for Control.Monad.Mock.


[Skip to Readme]
Versions [faq] 0.1.0.0, 0.1.1.0, 0.1.1.1, 0.1.1.2, 0.2.0.0
Dependencies base (>=4.9.0.0 && <5), constraints (>=0.3.1), exceptions (>=0.6), monad-control (>=1.0.0.0 && <2), mtl, transformers-base [details]
License ISC
Copyright 2017 CJ Affiliate by Conversant
Author Alexis King <lexi.lambda@gmail.com>
Maintainer Alexis King <lexi.lambda@gmail.com>
Category Testing
Home page https://github.com/cjdev/monad-mock#readme
Bug tracker https://github.com/cjdev/monad-mock/issues
Source repo head: git clone https://github.com/cjdev/monad-mock
Uploaded by lexi_lambda at Sat Jun 24 00:21:35 UTC 2017
Distributions NixOS:0.2.0.0
Downloads 1700 total (120 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2017-06-24 [all 1 reports]

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for monad-mock-0.1.0.0

[back to package description]

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 String
copyFile a b = do
  x <- readFile a
  writeFile b x
  return x

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

For more information, see the documentation on Hackage.