The monad-mock package

[Tags:library, test]

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]

Properties

Versions 0.1.0.0, 0.1.1.0, 0.1.1.1
Change log CHANGELOG.md
Dependencies base (>=4.9.0.0 && <5), constraints (>=0.3.1), exceptions (>=0.6), haskell-src-exts, haskell-src-meta, monad-control (>=1.0.0.0 && <2), mtl, template-haskell (>=2.11.0.0 && <2.13), th-orphans, 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 repository head: git clone https://github.com/cjdev/monad-mock
Uploaded Wed Jun 28 22:16:41 UTC 2017 by lexi_lambda
Distributions NixOS:0.1.1.1
Downloads 111 total (111 in the last 30 days)
Votes
0 []
Status Docs available [build log]
Last success reported on 2017-06-28 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Readme for monad-mock

Readme for monad-mock-0.1.1.1

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.