https://github.com/adetokunbo/benri-hspec
A small library of convenient functions for writing hspec tests
https://github.com/adetokunbo/benri-hspec
haskell haskell-library hspec
Last synced: 2 months ago
JSON representation
A small library of convenient functions for writing hspec tests
- Host: GitHub
- URL: https://github.com/adetokunbo/benri-hspec
- Owner: adetokunbo
- License: bsd-3-clause
- Created: 2022-11-10T10:05:04.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-01-20T08:31:59.000Z (4 months ago)
- Last Synced: 2025-02-11T04:32:42.307Z (3 months ago)
- Topics: haskell, haskell-library, hspec
- Language: Haskell
- Homepage: https://hackage.haskell.org/package/benri-hspec
- Size: 30.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.lhs
- Changelog: ChangeLog.md
- License: LICENSE
Awesome Lists containing this project
README
# benri-hspec
[](https://github.com/adetokunbo/benri-hspec/actions)
[](http://stackage.org/nightly/package/benri-hspec)
[![Hackage][hackage-badge]][hackage]
[![Hackage Dependencies][hackage-deps-badge]][hackage-deps]
[](https://github.com/adetokunbo/benri-hspec/blob/master/LICENSE)`benri-hspec` is a small library of __convenient__ functions for writing hspec tests.
It's simplifies test code that returns `Either` or `Maybe` types from monadic code.
## Example
```haskell
{-# LANGUAGE OverloadedStrings #-}import System.Environment
( lookupEnv,
setEnv,
unsetEnv
)
import Text.Read (readEither)
import Test.Hspec
import Test.Hspec.Benrispec :: Spec
spec = describe "Checking the functions in Test.Hspec.Benri" $ before_ clearIt $ do
context "endsJust_" $ do
it "should succeed if a Just is returned" $ do
setIt
endsJust_ getItcontext "endsJust" $ do
it "should match the Just value" $ do
setIt
getIt `endsJust` "1"context "endsNothing" $ do
it "should succeed when the action returns Nothing" $ do
setIt
getIt `endsJust` "1"
clearIt
endsNothing getItcontext "endsLeft_" $ do
it "should succeed if a Left is returned" $ do
setNotInt
endsLeft_ getAsIntcontext "endsLeft" $ do
it "should match the Left value" $ getAsInt `endsLeft` "not set!"context "endsRight_" $ do
it "should succeed if a Right is returned" $ do
setIt
endsRight_ getAsIntcontext "endsRight" $ do
it "should match the Right value" $ do
setIt
getAsInt `endsRight` 1context "endsThen" $ do
it "should implement the behaviour of the other functions easily" $ do
setIt
getIt `endsThen` (== (Just "1"))
clearIt
getIt `endsThen` (== Nothing)
getAsInt `endsThen` (== (Left "not set!"))
setIt
getAsInt `endsThen` (== (Right 1))getIt :: IO (Maybe String)
getIt = lookupEnv envNamegetAsInt :: IO (Either String Int)
getAsInt = maybe (Left "not set!") readEither <$> getItsetIt :: IO ()
setIt = setEnv envName "1"setNotInt :: IO ()
setNotInt = setEnv envName "foo"clearIt :: IO ()
clearIt = unsetEnv envNameenvName :: String
envName = "AN_ENV_VAR"main :: IO ()
main = hspec spec```
[hackage-deps-badge]:
[hackage-deps]:
[hackage-badge]:
[hackage]: