freckle-app 1.2.0.2 → 1.3.0.0
raw patch · 5 files changed
+62/−22 lines, 5 files
Files
- CHANGELOG.md +8/−1
- freckle-app.cabal +1/−1
- library/Freckle/App/Test.hs +44/−13
- package.yaml +1/−1
- tests/Freckle/App/MemcachedSpec.hs +8/−6
CHANGELOG.md view
@@ -1,4 +1,11 @@-## [_Unreleased_](https://github.com/freckle/freckle-app/compare/v1.2.0.2...main)+## [_Unreleased_](https://github.com/freckle/freckle-app/compare/v1.3.0.0...main)++## [v1.3.0.0](https://github.com/freckle/freckle-app/compare/v1.2.0.2...v1.3.0.0)++- Adjust `Freckle.App.Test` interface+ - Remove `runAppTest`+ - Add `appExample` for making a expectation concretely `AppExample`+ - Add `expectationFailure`, and `pending(With)` helpers in `MonadIO` ## [v1.2.0.2](https://github.com/freckle/freckle-app/compare/v1.2.0.1...v1.2.0.2)
freckle-app.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.18 name: freckle-app-version: 1.2.0.2+version: 1.3.0.0 license: MIT license-file: LICENSE maintainer: Freckle Education
library/Freckle/App/Test.hs view
@@ -5,14 +5,35 @@ module Freckle.App.Test ( AppExample(..)+ , appExample , withApp , withAppSql- , runAppTest+ , expectationFailure+ , pending+ , pendingWith++ -- * Re-exports , module X ) where -import Freckle.App.Prelude+import Freckle.App.Prelude as X +import Data.Pool as X+import Freckle.App.Database as X+import Test.Hspec as X+ ( Expectation+ , Spec+ , beforeAll+ , beforeWith+ , context+ , describe+ , example+ , fit+ , it+ , xit+ )+import Test.Hspec.Expectations.Lifted as X hiding (expectationFailure)+ import Blammo.Logging import Control.Monad.Base import Control.Monad.Catch@@ -22,15 +43,11 @@ import Control.Monad.Random (MonadRandom(..)) import Control.Monad.Reader import Control.Monad.Trans.Control-import Data.Pool as X import Database.Persist.Sql (SqlPersistT, runSqlPool)-import Freckle.App (runApp)-import Freckle.App.Database as X import LoadEnv-import Test.Hspec as X- (Spec, beforeAll, beforeWith, context, describe, example, fit, it, xit)+import qualified Test.Hspec as Hspec hiding (expectationFailure) import Test.Hspec.Core.Spec (Arg, Example, SpecWith, evaluateExample)-import Test.Hspec.Expectations.Lifted as X+import qualified Test.Hspec.Expectations.Lifted as Hspec (expectationFailure) -- | An Hspec example over some @App@ value --@@ -85,6 +102,17 @@ params ($ ()) +-- | A type restricted version of id+--+-- Like 'example', which forces the expectation to 'IO', this can be used to+-- force the expectation to 'AppExample'.+--+-- This can be used to avoid ambiguity errors when your expectation uses only+-- polymorphic functions like 'runDB' or lifted 'shouldBe' et-al.+--+appExample :: AppExample app a -> AppExample app a+appExample = id+ -- | Spec before helper -- -- @@@ -112,8 +140,11 @@ loadEnvTest :: IO () loadEnvTest = loadEnvFrom ".env.test" >> loadEnv --- | Run an action with the test @App@-runAppTest :: HasLogger app => ReaderT app (LoggingT IO) a -> AppExample app a-runAppTest action = do- app <- ask- liftIO $ runApp app action+expectationFailure :: MonadIO m => String -> m ()+expectationFailure msg = Hspec.expectationFailure msg >> error "unreachable"++pending :: MonadIO m => m ()+pending = liftIO Hspec.pending++pendingWith :: MonadIO m => String -> m ()+pendingWith msg = liftIO $ Hspec.pendingWith msg
package.yaml view
@@ -1,6 +1,6 @@ --- name: freckle-app-version: 1.2.0.2+version: 1.3.0.0 maintainer: Freckle Education category: Utils github: freckle/freckle-app
tests/Freckle/App/MemcachedSpec.hs view
@@ -4,7 +4,7 @@ ( spec ) where -import Freckle.App.Prelude+import Freckle.App.Test import Control.Lens ((^?!)) import Control.Monad.Reader@@ -16,7 +16,6 @@ import Freckle.App.Memcached.Client (MemcachedClient, newMemcachedClient) import qualified Freckle.App.Memcached.Client as Memcached import Freckle.App.Memcached.Servers-import Freckle.App.Test import Freckle.App.Test.Logging data ExampleValue@@ -37,14 +36,17 @@ "C" -> Right C x -> Left $ "invalid: " <> show x +-- |+--+-- NB. we could use 'withApp' and not need to call this runner ourselves within+-- an @'it'-'example'@ -- except that we want to use 'runCapturedLoggingT' and+-- assert on the logged messages. We should add "Blammo.Logging.Test" to support+-- this use-case.+-- runTestAppT :: MonadUnliftIO m => AppExample MemcachedClient a -> m (a, [Maybe Value]) runTestAppT f = liftIO $ do mc <- loadClient- -- NB. we could use `withApp` and not need to call this runner ourselves- -- within a plain-`IO` example -- except that we want to use- -- `runCapturedLoggingT` and assert on the logged messages. We should add- -- Blammo.Logging.Test to support this use-case. fmap (second $ map logLineToJSON) $ runCapturedLoggingT $ runReaderT (unAppExample f) mc