haskellmonadshspec

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 :: FileType -> IO (Either String String)

Solution

  • I do not know FileType, I deal it equals FilePath.

    use do and liftIO

    it "parse examples 0" $ do
      ex0in <- liftIO (tests "ex0in.txt")
      ex0out <- liftIO (tests "ex0Out.txt")
      ex0in `shouldBe` ex0out
    

    use join and liftIO

    it "parse examples 0" $ join $ liftM2 shouldBe (liftIO (tests "ex0in.txt")) (liftIO (tests "ex0Out.txt"))