Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/akshaymankar/polysemy-mocks
Mock polysemy effects
https://github.com/akshaymankar/polysemy-mocks
effects haskell haskell-library mock polysemy
Last synced: 24 days ago
JSON representation
Mock polysemy effects
- Host: GitHub
- URL: https://github.com/akshaymankar/polysemy-mocks
- Owner: akshaymankar
- License: bsd-3-clause
- Created: 2020-05-01T21:22:30.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T14:30:46.000Z (almost 2 years ago)
- Last Synced: 2024-03-15T05:44:43.413Z (8 months ago)
- Topics: effects, haskell, haskell-library, mock, polysemy
- Language: Haskell
- Size: 40 KB
- Stars: 3
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
- License: LICENSE
Awesome Lists containing this project
README
# Polysemy Mocks
## Overview
`polysemy-mocks` aims to provide a structure to write all mocks for polysemy and to generate those.
## Example
```haskell
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}module TeletypeSpec where
import Data.Kind
import Polysemy
import Polysemy.Internal (send)
import Test.Hspec
import Test.Polysemy.Mock
import Test.Polysemy.Mock.TH (genMock)
import Prelude hiding (read)data Teletype (m :: Type -> Type) a where
Read :: Teletype m String
Write :: String -> Teletype m ()makeSem ''Teletype
genMock ''Teletype
program :: Member Teletype r => Sem r ()
program = do
write "Name: "
name <- read
write $ "Hello " <> namespec :: Spec
spec =
describe "program" $ do
it "greets" $ runM @IO . evalMock $ do
mockReadReturns (pure "Akshay")
mock @Teletype @IO program
writes <- mockWriteCalls
embed $ writes `shouldBe` ["Name: ", "Hello Akshay"]
```