Questions tagged [hspec]

hspec is a behavior-driven Development for Haskell. It is a testing framework for Haskell.

Hspec is a testing framework for Haskell. It is roughly based on the Ruby library RSpec. Some of Hspec's distinctive features are:

  • A friendly DSL for defining tests
  • integration with QuickCheck, SmallCheck, and HUnit
  • parallel test execution
  • automatic discovery of test files

For more details click here

77 questions
15
votes
1 answer

Select which test to run with Hspec and stack

I've written a series of test, using the automatic spec discovery feature of Hspec. I'm also using stack as my build tool. My test directory has the the Spec.hs file, along with the test files for the different modules of my application (e.g.…
Damian Nadales
  • 4,907
  • 1
  • 21
  • 34
7
votes
1 answer

Access a value set up by `beforeAll` during tests

Here's what I've got: spec :: Spec spec = do manager <- runIO newManager it "foo" $ do -- code that uses manager it "bar" $ do -- code that usees manager The docs for runIO suggest that I should probably be using beforeAll instead,…
Dan Burton
  • 53,238
  • 27
  • 117
  • 198
5
votes
1 answer

Use HSpec and QuickCheck to verify Data.Monoid properties

I'm trying to use HSpec and QuickCheck to verify properties of Monoids (associativity and identity element). I am going to verify particular instances, but would like to keep most of the code polymorphic. This is what I came up with after several…
maciekszajna
  • 325
  • 1
  • 4
  • 9
4
votes
1 answer

hspec defined tests invoked with stack throw an error when test file is defined as a module

I'm trying to get my head around the reason why the test file containing unit-tests which is defined as a module fails when run with stack build --test. Say having a simple test module defined from scratch with: stack new test-module cd…
mjarosie
  • 3,228
  • 2
  • 20
  • 31
4
votes
1 answer

Unit testing IO actions with Hspec

I have found other questions on similar lines but nothing that answers my question in this particular scenario. Furthermore, there seem to be few resources which succinctly cover the subject of unit testing IO actions in Haskell. Let's say I have…
Alex
  • 8,093
  • 6
  • 49
  • 79
4
votes
1 answer

Using HSpec with Stack

I have the following architecture : backend ├── Chat.hs ├── Main.hs └── Message.hs test ├── backendSpec │ └── MessageSpec.hs └── Spec.hs My .cabal file contains the following test-suite spec build-depends: base, hspec ==…
Dref360
  • 628
  • 5
  • 9
3
votes
0 answers

Alternative instance for Tests?. HSpec

I'd like to write a test suite which expresses the following: function f either is not implemented or it is implemented with the some tests. So I can check both things separatelly. I'd like to do something like spec1 <|> spec2 where the alternative…
lsmor
  • 4,698
  • 17
  • 38
3
votes
1 answer

Using IO within a QuickCheck property test?

I'm currently writing a Haskell library to replace a closed-source 3rd party command line application. This 3rd party CLI has a spec that I've replicated, but the actually binary allows much more permissive inputs than the spec. I'd like to be able…
danielbeard
  • 9,120
  • 3
  • 44
  • 58
3
votes
2 answers

Why cannot I get `where` to work in Hspec

I'm struggling with the semantics of where within do blocks, specifically with Test.Hspec. The following works: module ExampleSpec where import Test.Hspec import Test.QuickCheck spec :: Spec spec = do describe "foo" $ do let …
3
votes
1 answer

How to select a value in a range with QuickCheck?

I have the following code I am using for creating a challenge on the following site : codewars describe "Random cases" $ do it "It should handle random test cases" $ property $ prop_check where prop_check (Positive x) =…
Any3nymous user
  • 216
  • 2
  • 11
3
votes
1 answer

Hspec: How to suppress successful test results

Is there anyway to prevent successful tests from being printed out to screen? At the moment I have a lot of tests with really long inputs and I only really care about seeing the fails? Edit: I am running my tests with stack test Solution: Thanks to…
matt
  • 1,817
  • 14
  • 35
3
votes
2 answers

Random tests generated by Haskell HSpec property

I am running tests with Hspec and Quickcheck http://hspec.github.io/ The provided example to execute a random test case is it "returns the first element of an *arbitrary* list" $ property $ \x xs -> head (x:xs) == (x :: Int) With…
brander
  • 121
  • 4
3
votes
2 answers

Is it possible with HSpec (or HUnit) to attach further information to assertions that get printed in and only in case of failure?

Similarly to how quickcheck supports counterexamples: property \x -> counterexample ("Foo failed with: " ++ ...) $ foo x but in a way that it works with shouldBe, e.g. failDetails (" details: " ++ baz a) $ a `shouldBe` 2 And I would like…
Wizek
  • 4,854
  • 2
  • 25
  • 52
3
votes
2 answers

How to do pending spec inside Yesod specs

I'm new to Yesod and I'm trying to add a pending spec within a withApp block (at the moment I'm just trying to modify the spec generated by the Yesod scaffholding). the code looks like : appSpec :: Spec appSpec :: withApp $ do describe…
mb14
  • 22,276
  • 7
  • 60
  • 102
3
votes
3 answers

testing functions that return a Maybe Monad

Say I have a function: safeHead :: [a] -> Maybe a safeHead [] = Nothing safeHead xs = Just $ head xs And a test: describe "Example.safeHead" $ do it "returns the head" $ do safeHead [1,2,3] `shouldBe` Just 1 it "returns Nothing for an…
Abraham P
  • 15,029
  • 13
  • 58
  • 126
1
2 3 4 5 6