hspec-expectations-lens 0.3.0.0 → 0.4.0
raw patch · 8 files changed
+210/−82 lines, 8 filesdep ~hspecdep ~lens
Dependency ranges changed: hspec, lens
Files
- CHANGELOG.markdown +35/−0
- CHANGELOG.md +0/−30
- LICENSE +1/−5
- README.lhs +0/−9
- README.markdown +8/−0
- hspec-expectations-lens.cabal +22/−13
- src/Test/Hspec/Expectations/Lens.hs +7/−25
- test/Test/Hspec/Expectations/LensSpec.hs +137/−0
+ CHANGELOG.markdown view
@@ -0,0 +1,35 @@+0.4.0+=======++ * Reflect API changes in `lens-4.7`++0.3.0.0+=======++ * Update to `lens-4.0`++0.2.1.1+=======++ * _Maintenance_: Upper bound on `lens`++0.2.1.0+=======++ * Add a `shouldPerform` expectation+ * Improve expectations' error messages++0.2.0.0+=======++ * Add a `shouldThrow` expectation, a lensy variant of `shouldThrow`++ * Add a `Test.Hspec.Lens` module, re-exporting `Test.Hspec` with+`Test.Hspec.Expectations.Lens` expectations++ * More documentation with fake type signatures++0.1.0.0+=======++ * `shouldHave`, `shouldNotHave`, `shouldView`, `shouldPreview`, and `shouldList`
− CHANGELOG.md
@@ -1,30 +0,0 @@-0.3.0.0-=======-- * Update to `lens-4.0`--0.2.1.1-=======-- * _Maintenance_: Upper bound on `lens`--0.2.1.0-=======-- * Add a `shouldPerform` expectation- * Improve expectations' error messages--0.2.0.0-=======-- * Add a `shouldThrow` expectation, a lensy variant of `shouldThrow`-- * Add a `Test.Hspec.Lens` module, re-exporting `Test.Hspec` with-`Test.Hspec.Expectations.Lens` expectations-- * More documentation with fake type signatures--0.1.0.0-=======-- * `shouldHave`, `shouldNotHave`, `shouldView`, `shouldPreview`, and `shouldList`
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2013, Matvey Aksenov+Copyright (c) 2013-2015, Matvey Aksenov All rights reserved. @@ -12,10 +12,6 @@ copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.-- * Neither the name of Matvey Aksenov nor the names of other- contributors may be used to endorse or promote products derived- from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
README.lhs view
@@ -1,7 +1,5 @@ hspec-expectations-lens =======================-[](http://hackage.haskell.org/package/hspec-expectations-lens)-[](http://travis-ci.org/supki/hspec-expectations-lens) hspec-expectations-lens is a set of expectations for [Hspec][hspec] with a [lens][lens]-compatible interface@@ -51,7 +49,6 @@ > module Main (main) where > > import Control.Lens-> import Data.List.Lens > import Control.Exception (evaluate) > import Control.Exception.Lens (_ErrorCall, _DivideByZero) > import Test.Hspec.Lens@@ -122,12 +119,6 @@ > describe "shouldPreview" $ > it "gets the first target" $ > [1..10] `shouldPreview` 10 `through` reversed.folded--`shouldPerform` performs the action and looks into the first target of the result.--> describe "shouldPerform" $-> it "performs an action and gets the first target" $-> readFile "README.lhs" `shouldPerform` 99 `through` to lines.folded.prefixed ">".to length The last combinator, which does not really belong to any of the previous groups, is `shouldThrow`. It uses composable selectors to determine which
+ README.markdown view
@@ -0,0 +1,8 @@+hspec-expectations-lens+=======================+[](https://hackage.haskell.org/package/hspec-expectations-lens)+[](https://travis-ci.org/supki/hspec-expectations-lens)++see [`README.lhs`][0]++ [0]: ./README.lhs
hspec-expectations-lens.cabal view
@@ -1,18 +1,19 @@ name: hspec-expectations-lens-version: 0.3.0.0+version: 0.4.0 synopsis: Hspec expectations for the lens stuff description: Package adds hspec expectations (@\`shouldX\`@ things) that work nicely with the "lens" library homepage: http://supki.github.io/hspec-expectations-lens/-license: BSD3+license: BSD2 license-file: LICENSE author: Matvey Aksenov maintainer: matvey.aksenov@gmail.com category: Testing build-type: Simple extra-source-files:- CHANGELOG.md+ CHANGELOG.markdown+ README.markdown README.lhs cabal-version: >= 1.10 @@ -22,30 +23,38 @@ source-repository this type: git- tag: 0.3.0.0+ tag: 0.4.0 location: https://github.com/supki/hspec-expectations-lens library- default-language: Haskell2010- hs-source-dirs: src+ default-language:+ Haskell2010+ hs-source-dirs:+ src build-depends: base == 4.* , hspec-expectations >= 0.5- , hspec >= 1.8- , lens >= 4.0+ , hspec >= 1.12+ , lens >= 4.7 , HUnit exposed-modules: Test.Hspec.Expectations.Lens Test.Hspec.Lens test-suite spec- type: exitcode-stdio-1.0- default-language: Haskell2010- hs-source-dirs: test- main-is: Spec.hs+ type:+ exitcode-stdio-1.0+ default-language:+ Haskell2010+ hs-source-dirs:+ test+ main-is:+ Spec.hs+ other-modules:+ Test.Hspec.Expectations.LensSpec build-depends: base == 4.* , hspec , hspec-expectations-lens- , lens >= 4.0+ , lens , silently
src/Test/Hspec/Expectations/Lens.hs view
@@ -7,7 +7,6 @@ , shouldPreview , shouldList , shouldThrow- , shouldPerform , through ) where @@ -24,7 +23,6 @@ infixl 1 `shouldHave`, `shouldNotHave` infixl 1 `shouldView`, `shouldPreview`, `shouldList` infixl 1 `shouldThrow`-infixl 1 `shouldPerform` infixl 1 `through` -- | @s \`shouldHave\` l@ sets the expectation that 'Fold' @l@ has@@ -121,12 +119,12 @@ -- only allows @e -> Bool@ selectors, which is less general and often less convenient -- -- @--- shouldThrow :: 'IO' a -> 'Getter' s b -> 'Expectation'--- shouldThrow :: 'IO' a -> 'Fold' s b -> 'Expectation'--- shouldThrow :: 'IO' a -> 'Lens'' s b -> 'Expectation'--- shouldThrow :: 'IO' a -> 'Iso'' s b -> 'Expectation'--- shouldThrow :: 'IO' a -> 'Traversal'' s b -> 'Expectation'--- shouldThrow :: 'IO' a -> 'Prism'' s b -> 'Expectation'+-- shouldThrow :: 'IO' a -> 'Getter' 'SomeException' b -> 'Expectation'+-- shouldThrow :: 'IO' a -> 'Fold' 'SomeException' b -> 'Expectation'+-- shouldThrow :: 'IO' a -> 'Lens'' 'SomeException' b -> 'Expectation'+-- shouldThrow :: 'IO' a -> 'Iso'' 'SomeException' b -> 'Expectation'+-- shouldThrow :: 'IO' a -> 'Traversal'' 'SomeException' b -> 'Expectation'+-- shouldThrow :: 'IO' a -> 'Prism'' 'SomeException' b -> 'Expectation' -- @ shouldThrow :: IO a -> Getting (First b) SomeException b -> Expectation x `shouldThrow` l = do@@ -135,23 +133,7 @@ Left _ -> return () Right _ -> assertFailure "Couldn't catch any exceptions" --- | @a \`shouldPerform\` t \`through\` l@ sets the expectation that @t@ is--- a target of the 'MonadicFold' @l@ applied to the result of action @a@------ @--- shouldPerform :: ('Show' a, 'Eq' a) => 'IO' s -> a -> 'Action' 'IO' s a -> 'Expectation'--- shouldPerform :: ('Show' a, 'Eq' a) => 'IO' s -> a -> 'MonadicFold' 'IO' s a -> 'Expectation'--- @-shouldPerform :: (Show a, Eq a) => IO s -> a -> Acting IO (Leftmost a) s a -> Expectation-(x `shouldPerform` t) l = do- r <- x ^!? acts.l- case r of- Nothing ->- assertFailure (printf "No targets, but expected %s" (show t))- Just r' -> unless (r' == t) $- assertFailure (printf "Resulted in %s, but expected %s" (show r') (show t))---- | A helper to fight parentheses+-- | `through` fights parentheses -- -- @ -- through ≡ id
+ test/Test/Hspec/Expectations/LensSpec.hs view
@@ -0,0 +1,137 @@+{-# LANGUAGE ExtendedDefaultRules #-}+module Test.Hspec.Expectations.LensSpec (spec) where++import Control.Lens+import Control.Exception+import Control.Exception.Lens+import System.IO.Silently+import Test.Hspec hiding (shouldThrow)+import Test.Hspec.Runner++import Test.Hspec.Expectations.Lens+++spec :: Spec+spec = do+ describe "shouldHave" $ do+ it "holds for a non-empty Traversal" $+ shouldHold $+ Just (Just 5, 't') `shouldHave` traverse._1.traverse++ it "holds for a non-empty Fold" $+ shouldHold $+ ("hi", [Nothing, Just 5, Nothing]) `shouldHave` _2.folded.folded++ it "holds for a non-empty Prisms" $+ shouldHold $+ Just (Right (Just 5)) `shouldHave` _Just._Right._Just++ it "does not hold for an empty Traversal" $+ shouldNotHold $+ [1..10] `shouldHave` traverse.filtered(> 10)++ it "does not hold for an empty Fold" $+ shouldNotHold $+ [1..10] `shouldHave` folded.filtered(> 10)++ it "does not hold for an empty Prism" $+ shouldNotHold $+ Just (Right (Just 5)) `shouldHave` _Just._Left._Just++ describe "shouldNotHave" $ do+ it "does not hold for a non-empty Traversal" $+ shouldNotHold $+ Just (Just 5, 't') `shouldNotHave` traverse._1.traverse++ it "does not hold for a non-empty Fold" $+ shouldNotHold $+ ("hi", [Nothing, Just 5, Nothing]) `shouldNotHave` _2.folded.folded++ it "does not hold for a non-empty Prism" $+ shouldNotHold $+ Just (Right (Just 5)) `shouldNotHave` _Just._Right._Just++ it "holds for an empty Traversal" $+ shouldHold $+ [1..10] `shouldNotHave` traverse.filtered(> 10)++ it "holds for an empty Fold" $+ shouldHold $+ [1..10] `shouldNotHave` folded.filtered(> 10)++ it "holds for an empty Prism" $+ shouldHold $+ Just (Right (Just 5)) `shouldNotHave` _Just._Left._Just++ describe "shouldView" $ do+ it "views the Lens target" $+ shouldHold $+ (1, ((2, 3), 4)) `shouldView` 3 `through` _2._1._2++ it "views the Getter target" $+ shouldHold $+ (1, ((2, 3), 4)) `shouldView` 3 `through` to snd.to fst.to snd++ describe "shouldPreview" $ do+ it "previews the first Lens target" $+ shouldHold $+ (1, ((2, 3), 4)) `shouldPreview` 3 `through` _2._1._2++ it "previews the first Getter target" $+ shouldHold $+ (1, ((2, 3), 4)) `shouldPreview` 3 `through` to snd.to fst.to snd++ it "previews the first Fold target" $+ shouldHold $+ Just (Right (Just 7)) `shouldPreview` 7 `through` folded._Right.folded++ it "previews the first Traversal target" $+ shouldHold $+ Just (Right (Just 7)) `shouldPreview` 7 `through` traverse._Right.traverse++ describe "shouldList" $ do+ it "lists Lens targets" $+ shouldHold $+ (1, ((2, 3), 4)) `shouldList` [3] `through` _2._1._2++ it "lists Getter targets" $+ shouldHold $+ (1, ((2, 3), 4)) `shouldList` [3] `through` to snd.to fst.to snd++ it "lists Fold targets" $+ shouldHold $+ [[1, 2, 3], [4, 5, 6]] `shouldList` [2, 4, 6] `through` folded.folded.filtered even++ it "lists Traversal targets" $+ shouldHold $+ [[1, 2, 3], [4, 5, 6]] `shouldList` [1, 3, 5] `through` traverse.traverse.filtered odd++ describe "shouldThrow" $ do+ it "catches ErrorCall" $+ shouldHold $+ error "hi" `shouldThrow` _ErrorCall++ it "catches fine-grained ErrorCall" $+ shouldHold $+ error "hi" `shouldThrow` _ErrorCall.only "hi"++ it "does not catch exceptions which selector does not match" $+ shouldNotHold $+ error "bye" `shouldThrow` _ErrorCall.only "hi"++ it "catches DivideByZero" $+ shouldHold $+ evaluate (1 `div` 0) `shouldThrow` _DivideByZero+++shouldResultIn :: Expectation -> String -> IO ()+shouldResultIn expectation result = do+ r <- fmap (last . lines) . capture_ . hspecWithResult defaultConfig $+ it "" expectation+ r `shouldBe` result++shouldHold :: Expectation -> Expectation+shouldHold = (`shouldResultIn` "1 example, 0 failures")++shouldNotHold :: Expectation -> Expectation+shouldNotHold = (`shouldResultIn` "1 example, 1 failure")