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

[ library, testing ] [ Propose Tags ] [ Report a vulnerability ]

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]

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.1.0, 0.1.1.1, 0.1.1.2, 0.2.0.0
Change log CHANGELOG.md
Dependencies base (>=4.8.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.10.0.0 && <2.13), th-orphans, transformers, 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 2017-09-14T17:11:13Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 3390 total (5 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-09-14 [all 1 reports]

Readme for monad-mock-0.2.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 ()
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.