3

I'm new to Yesod and I'm trying to add a pending spec within a withApp block (at the moment I'm just trying to modify the spec generated by the Yesod scaffholding).

the code looks like :

appSpec :: Spec appSpec :: withApp $ do describe "getMyHandlerR" $ do it "todo" $ do pending

But I got the following error message :

Couldn't match type ‘(App, wai-3.2.0:Network.Wai.Middleware)’
               with ‘()’
Expected type: SpecWith (TestApp App)
  Actual type: SpecWith (Arg Expectation)
In a stmt of a 'do' block: it "todo" $ do { pending }
In the second argument of ‘($)’, namely
  ‘do { it "todo" $ do { pending } }’
In a stmt of a 'do' block:
  describe "upload a file without error"
  $ do { it "todo" $ do { pending } }

If I remove the withApp everything works. I understand withApp is changing somehow the expected type but how come describe and it have the correct type whereas pending doesn't ?

mb14
  • 22,276
  • 7
  • 60
  • 102
  • 1
    I think you just need to throw away the `TestApp App` argument via `it "todo" $ \_ -> pending` or `it "todo" $ const pending` – Michael Snoyman Apr 11 '16 at 14:32
  • 1
    I can confirm @MichaelSnoyman's fix works – MaxGabriel Apr 11 '16 at 15:02
  • Wow, it works indeed. I tried `liftIO` but without success. I'm still surprised that `it "" pending` works outside of `withApp` but doesn't inside, there is probably some type inference magic there. @MichaelSnoyman could you post is as an answer so I can accept it ? Wouldn't it be worth doing adding a `ypending` or equivalent ? – mb14 Apr 11 '16 at 16:35

2 Answers2

3

Copying my comment to an answer:

I think you just need to throw away the TestApp App argument via:

it "todo" $ \_ -> pending

or

it "todo" $ const pending

Wouldn't it be worth doing adding a ypending or equivalent?

Sounds like a good idea to me, I've actually never personally used pending which is why I'd never thought of it. Would you be able to send a PR to get that included?

Michael Snoyman
  • 31,100
  • 3
  • 48
  • 77
  • I'm happy to do a pull request for it. However should it be ypending like yit ? I still don't understand why normal pending dosenst work in a normal it block ( not a yit block) – mb14 Apr 12 '16 at 06:34
  • Because the type of `pending` is `Expectation`, which is `IO ()`, not allowing for the extra argument. I don't fully understand the type magic in hspec, but it is present. – Michael Snoyman Apr 12 '16 at 09:52
  • I had a look and it's more tricky that I thought. doing `ypending = const pending` doesn't work in a `yit` context which anyway I'm not using. I understand enough of `yit` to do anything at the moment.IThere are type families involved in Hspec, which explains the magic. It might possible to modify `withApp` from the scaffolding to accept pending without the const. – mb14 Apr 12 '16 at 20:01
  • this is a more general issue than OPs that I fought with for a few hours, trying to get App-independent tests to work, and it'd be useful for my fellow Yesod newbies to have access to this in testing-relevant documentation, if possible! – Josh.F Feb 02 '17 at 00:02
1

This works like a charm for me with latest Yesod:

it "should x" $ do
  liftIO pending
Wizek
  • 4,854
  • 2
  • 25
  • 52