dimanche 26 août 2018

Haskell: How to test a Spock app that uses wreq?

I've written a very simple app in Haskell using Spock and wreq. I want to write some tests, but I'm not sure how to do it.

All the app does is make an HTTP request to another server and translate the JSON response into a human-friendly message. Here is the code if it helps. I want to write a test that asserts the human-friendly message is correct given a certain JSON response.

In Ruby, I would mock out the HTTP client, in this case wreq, to control the JSON response I get, but I'm not sure how, or even if, to do that in Haskell.

From what I've gathered out of my research, it sounds like type-class-constrained type variables are the way to go, which looks like dependency injection to me, but I'm unsure how to do this within the context of Spock and wreq.

The Spock testing tutorial describes how to test Spock at the IO Application level which is sounds great. The part I'm unsure about it how to "inject" a mock HTTP client to control the JSON response.

Any help is appreciated!

Aucun commentaire:

Enregistrer un commentaire