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
3
votes
1 answer

HSpec Nothing expectation failing to compile

I'm learning Haskell and I've written this function: safeHead :: [a] -> Maybe a safeHead [] = Nothing safeHead (x:xs) = Just x I'm now trying to test it with HSpec: import Test.Hspec main :: IO () main = hspec spec spec :: Spec spec = describe…
Galder Zamarreño
  • 5,027
  • 2
  • 26
  • 34
3
votes
1 answer

Supplying options to HSpec from Cabal

I'm trying to get started with hspec. I've got a working case working with QuickCheck, but I would just like some more detail when running cabal test. I found this article from hspec, giving instructions on supplying some more detailed control when…
Athan Clark
  • 3,886
  • 2
  • 21
  • 39
3
votes
2 answers

How can I easily express that I don't care about a value of a particular data field?

I was writing tests for my parser, using a method which might not be the best, but has been working for me so far. The tests assumed perfectly defined AST representation for every code block, like so: (parse "x = 5") `shouldBe` (Block [Assignment…
Bartek Banachewicz
  • 38,596
  • 7
  • 91
  • 135
3
votes
2 answers

Haskell - assert a function was called

Is it possible to verify that a function was called in Haskell HSpec? Assuming I had two functions foo and bar that transform my data. foo :: Stuff -> Stuff bar :: Stuff -> Stuff And I have a function that applies either foo or bar on Stuff …
Mukiza Andrew
  • 763
  • 1
  • 8
  • 17
2
votes
1 answer

Why am I getting an ioctl error in Visual Studio but not in Stack while trying to implement multiple test files in Hspec?

I am trying to implement a multi-spec file testing suite for a project in Haskell, using hspec-discover: -- this goes in Spec.hs {-# OPTIONS_GHC -F -pgmF hspec-discover #-} This should allow me to use multiple files of the form *spec.hs, but…
Azathoth
  • 33
  • 5
2
votes
0 answers

How to integrate/lift/inject custom monad stack with HSpec?

Context I have some monadic functions for an interpreter that I'm trying to test with HSpec. They run with the following monad stack: type AppState = StateT InterpreterState (ExceptT Events IO) type AppReturn a = Either Events (a, PState) runApp ::…
ATOMP
  • 1,311
  • 10
  • 29
2
votes
1 answer

Getting started with HSpec and Tasty in Haskell?

I'm new to Haskell and I'm trying to get hspec working with Tasty (using tasty-hspec) with Stack. I've seen an example of using tasty with HUnit which looks like this: import Test.Tasty import Test.Tasty.SmallCheck as SC import Test.Tasty.QuickCheck…
Johan
  • 37,479
  • 32
  • 149
  • 237
2
votes
1 answer

Could not find module ‘Test.Hspec.Discover’

I am a noob. I have tried to copy and paste a single Hspec/QuickCheck test out of a bigger project into my own so I can tweak it and see how it behaves. I have a structure like: myproject/test/Spec.hs myproject/test/mytest.hs Copying from the other…
Anentropic
  • 32,188
  • 12
  • 99
  • 147
2
votes
1 answer

Multiple before functions in HSpec?

I have an in-memory repository that I can create by calling this function: newEmptyRepository :: IO InMemoryGameRepository where InMemoryGameRepository is defined like this: type State = (HashMap GameId Game) type IORefState = IORef State newtype…
Johan
  • 37,479
  • 32
  • 149
  • 237
2
votes
1 answer

hspec test arguments work on command line but not from .hspec file

I am following the hspec documentation on passing options to Hspec. Specifying my option works as expected when passed from the command line, but not when passed from the .hspec file or any of the other listed methods. One of the tests in my test…
mherzl
  • 5,624
  • 6
  • 34
  • 75
2
votes
1 answer

How does "import Database.Persist as X hiding (get)" from the yesod-sqlite template works

I am using the yesod-sqlite template and trying to use the get function from Database.Persist in a test. Here is my code: [Entity _ task] <- runDB $ selectList [TaskName ==. name] [] ... user <- runDB $ X.get (taskUserId task) And the error I am…
2
votes
1 answer

Testing a typeclass with MonadIO: "No instance nor default method" error

I have a typeclass that performs some IO. I've generalised it a little using MonadIO: class MonadIO m => MonadDB m where getSomething :: String -> m Something getSomething s = -- do some IO stuff with liftIO In a test I wish to replace the…
Alex
  • 8,093
  • 6
  • 49
  • 79
2
votes
1 answer

Unit-testing the undefined evaluated in lazy expression in Haskell

Writing a unit test in Haskell where an expression should fail when undefined is encountered is a bit tricky. I tried the following with HSpec: module Main where import Test.Hspec import Control.Exception (evaluate) main :: IO () main = hspec $…
Artem Oboturov
  • 4,344
  • 2
  • 30
  • 48
2
votes
1 answer

Controlling how test data is generated in QuickCheck 2

I have a problem similar to this question Controlling how test data is generated in QuickCheck. Below I will articulate my specifics, the code I am using, and the particular question I have. I have written a fizz-buzz program that uses a Fibonacci…
user1198582
2
votes
1 answer

Issue with Aeson or Wai.JSON QuasiQuoter -- Converts 0.0 to 0

I am using Test.Hspec.Wai.JSON to check the return value of my api endpoints. I noticed that whenever i create a json with a value of 0.0, when the test runs, it converts it to 0 (Int) and if the api returns 0.0, the test fails. let j =…
Ecognium
  • 2,046
  • 1
  • 19
  • 35