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

Write nested assertions with Hspec

Ihm struggling to implement a seemingly simple testing problem with HSpec: I'd like to test a function myFunc :: (Exception e) a -> Either e MyRecord In one test case, I'd like to first assert that the return value is a Right value, then unwrap the…
Ulrich Schuster
  • 1,670
  • 15
  • 24
0
votes
0 answers

Import a test utils module from the test package with cabal

I have the following project structure: project + src |___ Func.hs + test |___ ASpec.hs |___ BSpec.hs |___ Spec.hs |___ Utils.hs I would like to import Utils module from ASpec and BSpec, sadly by default it seems to not be possible. I have also…
GlinesMome
  • 1,549
  • 1
  • 22
  • 35
0
votes
1 answer

Testing the state updates of a wai application

I have an application written on top of Wai, configured to have some custom state and be testable with Test.Hspec.Wai. I can test request/response interactions, but I haven't been able to figure out how to test for state changes; specifically, if my…
Tomas Aschan
  • 58,548
  • 56
  • 243
  • 402
0
votes
3 answers

Testing if a reader monad is called in the wrong environment

I have a MonadReader that generates data for an application I am working on. The main monad here generates the data based on some environment variables. The monad generates the data by selecting one of several other monads to run based on the…
Wheat Wizard
  • 3,982
  • 14
  • 34
0
votes
1 answer

Testing with Hakyll's MonadMetadata

For our Hakyll codebase, I've written a few helper methods and have started adding some HSpec unit tests around newer ones e.g.: -- | Reject an item unless @fieldName@ is set to "true" unlessEnabled :: MonadMetadata m => String …
declension
  • 4,110
  • 22
  • 25
0
votes
1 answer

Hspec & QuickCheck - Ambiguous type variable a0?

I have written a function in Haskell that takes a list of arbitrary elements and returns (mapped) a list of tuples. Each tuple contains the original element and a fraction, with all the fractions in the list adding to 1 (therefore I simply calculate…
Raiden616
  • 1,545
  • 3
  • 18
  • 42
0
votes
1 answer

Hspec deal with two IO actions in Haskell

My question is whether there are ways to test two IO actions in HSpec of Haskell? Just something like the below example: (The below is wrong because of type) it "parse examples 0" $ liftM2 shouldBe (tests "ex0in.txt") (tests "ex0Out.txt") tests…
handora
  • 559
  • 5
  • 14
0
votes
3 answers

Match "any string" in Haskell record in HSpec test

I have a data class Entity which is defined like this: data Entity = Entity { id :: String, name :: String } and a function that returns IO Entity: newPersistentEntity :: String -> IO Entity And I'd like to write an HSpec test for this: spec ::…
Johan
  • 37,479
  • 32
  • 149
  • 237
0
votes
1 answer

Haskell Hspec - only run expensive test on command line flag

I want to run an expensive Hspec test only when some flag on the command line is set for stack test. I understand that I can use stack test --test-arguments=... but what would I use on the command line and how would I carry out the conditional…
Rob Murray
  • 1,773
  • 6
  • 20
  • 32
0
votes
0 answers

How to test result of Control.Exception.Assert with HSpec

I want to use Control.Exception.Assert to get custom error messages. And I want to test these with HSpec. In the repl I can see: λ: import Control.Exception λ: import Control.Exception.Assert λ: (byEq assert "Bool" True True…
haroldcarr
  • 1,523
  • 15
  • 17
0
votes
0 answers

Create arbirtrary data in Hspec examples

When I run my Hspec test suite, it mentions the random seed that it used for that run. I assume it’s using that seed for the properties, but I’d also like to use it to generate arbitrary examples in my non-property examples. How would I go about…
Jason Whittle
  • 751
  • 4
  • 23
0
votes
1 answer

Comparing Two Mutually Recursive Values for Equality in HSpec is Causing Problems

1 The Context Consider the following snippet of Haskell: data T = T { f1 :: String , f2 :: T } deriving (Eq, Show) r1 = T { f1 = "val1" , f2 = r2 } :: T r2 = T { f1 = "val2" , f2 = r1 } ::…
George
  • 6,927
  • 4
  • 34
  • 67
0
votes
2 answers

cabal misconfiguration for tests

My .cabal file contains the following hspec configuration: -- The name of the package. name: MyModule version: 0.1.0.0 cabal-version: >=1.10 ... test-suite my-tests ghc-options: -Wall -Werror …
Abraham P
  • 15,029
  • 13
  • 58
  • 126
0
votes
1 answer

Running HUnit tests with Hspec

I want to run HUnit tests inside a spec: module SHCSpec (spec) where import Test.Hspec import Test.Hspec.Contrib.HUnit import Test.HUnit import SHC.Types import SHC.Lix spec :: Spec spec = do fromHUnitTest ("SHC.Lix" ~: "toHit" ~: …
rubik
  • 8,814
  • 9
  • 58
  • 88
0
votes
1 answer

Unit test main function: imports itself error

I'm trying to write a (small) executable, setup using Cabal, unit tested using HSpec. Almost all of my code is in a separate module, Library, including the body of main, which I import into my Main module as the run function -- In…
Michal Charemza
  • 25,940
  • 14
  • 98
  • 165