1

I'm trying to enhance my current test fixtures with passing more than just foundation (of type App) into hspec test cases. In the example below I'm passing an additional Text value inside of a tuple (as IO (App, Text) ) as opposed to directly returning IO App

beforeOp :: IO (App, Text)
beforeOp = do
  settings <- loadAppSettings
    ["config/test-settings.yml", "config/settings.yml"]
    []
    ignoreEnv
  foundation <- makeFoundation settings
  wipeDB foundation
  setUpFixtures foundation
  return (foundation, "foo")

innerSpec :: SpecWith (App, Text)
innerSpec = do
  describe "stuff" $ do
    it "should work" $ do
      post MyRouteR
      statusIs 403

spec :: Spec
spec = before beforeOp innerSpec

I can't figure out how to correctly structure innerSpec in such a way that I can do my normal Yesod testing with functions such as post, statusIs etc, but also have the Text value be available to those specs for reading.

Without Yesod I can do something along the lines of the following:

innerSpec :: SpecWith (Int, Int)
innerSpec = do
  describe "stuff" $ do
    it "should work" $ \(x, y) -> do
      x `shouldBe` y

and it will build just fine, but I can't quite get the types right as soon as Yesod comes into the mix. Advice?

Alexandr Kurilin
  • 7,685
  • 6
  • 48
  • 76
  • I think you need to use the `before` function from hspec to make this work, something like `\(x, y) -> before (return x) $ ...` – Michael Snoyman Mar 01 '15 at 10:01

0 Answers0