After staring at this for 20 minutes: I agree, this is confusing, but the
confusing part seems to be in hspec-snap -- why would it expect you to
provide a handler with routes? That's provided by the framework.
Test.snap should be using runSnaplet to get the app routes from the
framework. Otherwise, as you've discovered, additional routes specified in
the initializer routine will get blown away (because the resulting
generated site handler is not invoked). Right now we are not exporting the
routine needed in the public interface (here "is" is InitializerState which
hspec gets from getSnaplet):
let handler = runBase (_hFilter is $ route $ _handlers is) snapletMVar
We should probably export this function as a toplevel so hspec can use it.
On Mon, Feb 19, 2018 at 12:42 PM, Christian Goldammer <
> I'm using hspec-snap (https://hackage.haskell.org/
> package/hspec-snap-184.108.40.206/docs/Test-Hspec-Snap.html) to write unit tests
> for my snap application. I'm running into problems with routes. It's very
> possible that I'm overlooking something simple, many thanks for your help!
> My app looks roughly as follows:
> app :: SnapletInit App App
> app = do
> a <- nestSnaplet "api" api $ apiInit
> addRoutes routes
> return $ App a
> routes = [("login", handleLogin), ..]
> The api snaplet has additional routes (using servant, but I don't think
> that should matter here). I can set up unit testing as follows:
> tests = Test.snap (route routes) app $ do
> .. running tests here ..
> But the problem is that, when I run these tests, only the routes that are
> specified as part of `routes` are reachable. I find this confusing. First
> of all, why are routes required? The `app` snaplet already adds routes. The
> bigger problem is that I can't reach the routes that are part of the nested
> `api` snaplet, so I don't have a way of testing that functionality.
> Thanks, Chris
> You received this message because you are subscribed to the Google Groups
> "Snap Framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to snap_framework+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Gregory Collins <g...@gregorycollins.net>
You received this message because you are subscribed to the Google Groups "Snap
To unsubscribe from this group and stop receiving emails from it, send an email
For more options, visit https://groups.google.com/d/optout.