polysemy-mocks: Mocking framework for polysemy effects

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Please see the README on GitHub at https://github.com/akshaymankar/polysemy-mocks#readme


[Skip to Readme]

Properties

Versions 0.1.0.0, 0.1.0.1, 0.1.0.1, 0.2.0.0, 0.3.0.0, 0.3.1.0
Change log ChangeLog.md
Dependencies base (>=4.7 && <5), polysemy, template-haskell [details]
License BSD-3-Clause
Copyright 2020 Akshay Mankar
Author Akshay Mankar
Maintainer itsakshaymankar@gmail.com
Category Testing
Home page https://github.com/akshaymankar/polysemy-mocks#readme
Bug tracker https://github.com/akshaymankar/polysemy-mocks/issues
Source repo head: git clone https://github.com/akshaymankar/polysemy-mocks
Uploaded by axeman at 2021-02-19T21:20:40Z

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for polysemy-mocks-0.1.0.1

[back to package description]

Polysemy Mocks

Overview

polysemy-mocks aims to provide a structure to write all mocks for polysemy and to generate those.

Example

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# 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 " <> name

spec :: 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"]