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

Hspec: discovery, custom main, and passing argument to spec

I am trying to use hspec-discover along with custom Main. Custom Main is a bracket that creates a file descriptor to be used by all Spec's. This is my Spec.hs: {-# OPTIONS_GHC -F -pgmF hspec-discover -optF --module-name=Spec #-} This is my…
crosser
  • 717
  • 4
  • 17
2
votes
1 answer

No instance for (Show a0) arising from a use of ‘shouldBe’

I'm new to haskell and I'm trying to learn hspec at the same time. module ExercisesSpec where import Test.Hspec import Test.QuickCheck import Control.Exception (evaluate) halve :: [a] -> ([a], [a]) halve xs = splitAt (length xs `div` 2) xs main…
Jonny Appleseed
  • 121
  • 1
  • 8
1
vote
1 answer

Cases involving empty lists does not compile when using Filter to remove Nothing cases

For an assignment I have to write a function that uses filter on a list of Maybe instances, removing all with a value of Nothing. We're supposed to make sure the function works using Hspec. It's simple to get it working with a case containing…
Azathoth
  • 33
  • 5
1
vote
1 answer

Simplify incomplete assertions in HSpec

I want to unit-test a function that returns a complex nested data structure, but I'm only interested in certain fields of that structure. For example: expectedResult = Right ( UserRecord { name = "someName", id = address =…
Ulrich Schuster
  • 1,670
  • 15
  • 24
1
vote
1 answer

Hspec - snapshot testing in Haskell?

Is there a build-in possibility to create snapshot tests in hspec testing framework? With snapshot, I mean, that the output of a function can be compared to an expected output stored in a file. Or is there a hackage package to enable this feature?
1
vote
0 answers

Haskell: how to test that assertion exceptions are raised by a lifted function, using Tasty & Hspec

I'm very much still a beginner at Haskell. I learn best by trying things out, but sometimes I feel like I'm missing something fundamental. This is one of those times. I have some code that calls Control.Exception.assert but the Assertion exception…
davidA
  • 12,528
  • 9
  • 64
  • 96
1
vote
1 answer

How can I log HSpec test output through two formatters simultaneously?

I run my HSpec tests both locally and in the CI. The default specdoc formatter produces nice, colored stdio output. However, for the CI, I need the results in the XML format so that they can be presented on the web. I added my XML format to the…
Bartek Banachewicz
  • 38,596
  • 7
  • 91
  • 135
1
vote
1 answer

Checking each URL works in tests on a Yesod site

I was trying to check that all links work on a Yesod website home page. I wrote this hSpec test. module Handler.HomeSpec (spec) where import Data.Either (fromRight) import qualified Data.Text as T import …
zigazou
  • 1,725
  • 9
  • 13
1
vote
1 answer

How to write data-driven tests using Hspec?

I'm learning Haskell, and being a good developer, writing unit tests as I go. I implemented various sorting algorithms, and corresponding tests. However, I feel that separate tests are redundant, because the input and output are not varying, only…
Abhijit Sarkar
  • 21,927
  • 20
  • 110
  • 219
1
vote
0 answers

How to begin and rollback a transaction with hspec?

I am trying to write a test using hspec involving postgres transaction rollback as with postgresql-simple's begin and rollback commands. However, applying postgresql-simple's begin and rollback commands appears to cause my 'insert' command not to…
mherzl
  • 5,624
  • 6
  • 34
  • 75
1
vote
0 answers

Quickcheck specification DSL

I want to create a human readable DSL which non-haskell programmer could understand for creating specifications for black-box testing of external systems. And I wonder if something like this is possible to do in Haskell. action = readProcess "sleep…
user1685095
  • 5,787
  • 9
  • 51
  • 100
1
vote
0 answers

Explanation of `stack test --test-arguments "-m """`

On other forum pages, I've seen that I can run specific hspec tests with the command stack test --test-arguments "-m """ where is set to match it's textual descriptor for the intended tests. I frequently use this command to run…
mherzl
  • 5,624
  • 6
  • 34
  • 75
1
vote
1 answer

Testing user input with Hspec

I have a program that takes a user input from getLine then validates that it is all numbers. If it passes it runs a function of String -> String and prints the result to screen. If not it repeats the getLine. module Main where import…
matt
  • 1,817
  • 14
  • 35
1
vote
1 answer

Testing Acid-State with hspec

i'm a haskell noob and have problems with testing functions with acid-states.This ist my Datastructure data UserState = UserState { name :: String } deriving (Eq, Ord, Read, Show, Data, Typeable) and this is the function i want to test: setName…
alex.b
  • 184
  • 1
  • 2
  • 15
1
vote
1 answer

Abstracting Hspec tests

I am going through "Haskell programming from first principles" and I found myself writing code in the following fashion over and over: type IntToInt = Fun Int Int type TypeIdentity = ConcreteFunctorType Int -> Bool type TypeComposition =…
D. Amoroso
  • 170
  • 2
  • 10