Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- newtype MockT m a = MockT {
- st :: StateT [Definition] m a
- data Definition = forall f p sym.KnownSymbol sym => Definition {}
- runMockT :: MonadIO m => MockT m a -> m a
- applyTimesIs :: Monad m => MockT m () -> Int -> MockT m ()
- neverApply :: Monad m => MockT m () -> MockT m ()
Documentation
MockT | |
|
data Definition Source #
forall f p sym.KnownSymbol sym => Definition | |
runMockT :: MonadIO m => MockT m a -> m a Source #
Run MockT monad. After run, verification is performed to see if the stub function has been applied.
import Test.Hspec
import Test.MockCat
...
class (Monad m) => FileOperation m where
writeFile :: FilePath -> Text -> m ()
readFile :: FilePath -> m Text
operationProgram ::
FileOperation m =>
FilePath ->
FilePath ->
m ()
operationProgram inputPath outputPath = do
content <- readFile inputPath
writeFile outputPath content
makeMock [t|FileOperation|]
spec :: Spec
spec = do
it "test runMockT" do
result <- runMockT do
_readFile $ "input.txt" |> pack "content"
_writeFile $ "output.text" |> pack "content" |> ()
operationProgram "input.txt" "output.text"
result shouldBe
()
applyTimesIs :: Monad m => MockT m () -> Int -> MockT m () Source #
Specify how many times a stub function should be applied.
import Test.Hspec import Test.MockCat ... class (Monad m) => FileOperation m where writeFile :: FilePath -> Text -> m () readFile :: FilePath -> m Text operationProgram :: FileOperation m => FilePath -> FilePath -> m () operationProgram inputPath outputPath = do content <- readFile inputPath when (content == pack "ng") $ writeFile outputPath content makeMock [t|FileOperation|] spec :: Spec spec = do it "test runMockT" do result <- runMockT do _readFile ("input.txt" |> pack "content") _writeFile ("output.text" |> pack "content" |> ())applyTimesIs
0 operationProgram "input.txt" "output.text" resultshouldBe
()