Commit Graph

269 Commits

Author SHA1 Message Date
patrick brisbin
24acd4e3b7
Add missing HasCallStack
Even though functions that use this one all have HasCallStack, the fact
that this function itself doesn't means that all errors are reported as
from this line anyway:

    Failures:

      ./Yesod/Test.hs:1571:28:
      1) ...

This should correct that.
2020-12-01 11:49:29 -05:00
Felix Yan
672b82d510
Drop dependency on semigroups
They are not needed on GHC we support.
2020-08-02 17:30:19 +08:00
Maximilian Tagher
1d67e3a359 1.6.10 2020-06-21 20:27:35 -04:00
Maximilian Tagher
28e5b606b2 attempt to fix 8.2 2020-06-20 17:27:13 -04:00
Maximilian Tagher
4ddff42847 .. 2020-06-20 15:01:51 -04:00
Maximilian Tagher
f50d23ce49 .. 2020-06-20 15:01:26 -04:00
Maximilian Tagher
8f00e76257 .. 2020-06-20 14:56:19 -04:00
Maximilian Tagher
34927e3401 .. 2020-06-20 14:54:31 -04:00
Maximilian Tagher
2ddc63e66a When statusIs fails, print a preview of the body
My team makes frequent use of `statusIs`, but in virtually all cases where `statusIs` fails, we need to add a call to `printBody` to do further debugging.

Following in the footsteps of `requireJSONResponse`, this PR automatically prints a portion of the body when `statusIs` fails, assuming the body looks like a text-based response (e.g. not a JPEG).

I've found that a status code alone is often very misleading and leads people on a wild good chase, because e.g. a 403 could be triggered for many different reasons.

I'm opening this PR as a draft to confirm people like the idea of doing this. If so I'll do a closer review of the code (this is my first draft basically), and also write some tests + test the code works in all cases.
2020-06-17 17:31:00 -04:00
Maximilian Tagher
e7cf662af7 Update yesod-test cabal file for distribution
Hackage is now requiring a higher cabal file version, and with that comes a requirement to specify the language of each module
2020-06-01 14:54:39 -04:00
Maximilian Tagher
d03c095b63 Add bumped GHC dependency in yesod-test changelog 2020-06-01 11:53:03 -04:00
Maximilian Tagher
5c33dcb518 .. 2020-05-31 16:56:09 -04:00
Maximilian Tagher
8e89ec0e40 .. 2020-05-31 16:38:48 -04:00
Maximilian Tagher
ab8a994a34 .. 2020-05-31 16:38:09 -04:00
Maximilian Tagher
c3fa2adddd Add more documentation to yesod-test
This adds high-level documentation to yesod-test, plus some function documentation
2020-05-31 16:35:27 -04:00
Michael Snoyman
804b114d91
Drop LTS 9 2020-01-07 13:36:58 +02:00
Maximilian Tagher
4f51153b09 Require latest yesod-core for yesod-test
(This was missing from #1646)
2019-12-01 08:06:10 -05:00
Maximilian Tagher
8ee771896c .. 2019-11-29 10:46:25 -05:00
Maximilian Tagher
561adc2e17 .. 2019-11-29 10:44:49 -05:00
Maximilian Tagher
42d41f77de .. 2019-11-29 10:43:11 -05:00
Maximilian Tagher
0025226af6 Print preview of JSON body in case of parse failure 2019-11-28 22:33:00 -05:00
Maximilian Tagher
91b75741dd .. 2019-11-24 16:11:50 -05:00
Maximilian Tagher
92afb1150a .. 2019-11-24 15:56:42 -05:00
Maximilian Tagher
596db81d7a .. 2019-11-24 15:55:58 -05:00
Maximilian Tagher
6d0b723eb1 [yesod-test] Adds requireJSONResponse function
This function checks that a response body is JSON, and parses it into a Haskell value. Having something like this function is pretty essential to using Yesod as a JSON API server, so I think it's a good addition. You can use it to parse a Haskell record directly (usually by adding FromJSON classes to your response types), or parse a Value and pull out individual fields, maybe using something like `aeson-lens` (though probably a testing-specific library would be better).

I debated over these things:

1. The name. I was thinking of something like [assert/require/decode/parse]JSON[Response/Body]. I ultimately went with requireJSONResponse:
	- decode/parse sound like the aeson functions that return Either or Maybe, and I wanted this function to throw an error if it failed
	- I'm open to using `assertJSONResponse`—it matches the other functions (`assertEq`) better—but I think it reads less like English.
	- I chose Response over Body because (a) It also checks the content-type header, which is not in the body (b) "Body" felt slightly in-the-weeds of HTTP; I think "response" is more approachable.
2. Should it require the JSON content type? You can definitely have a server that returns JSON without JSON content types, but I think that's a such a bad idea, it's more likely requiring it helps people if they accidentally don't add the header.
3. Should it take a String parameter to add to the error message? This would match `assertEq`, but other functions like `statusIs` don't take a message. Ultimately I went without it, because the messages felt like I was repeating myself: `(comment :: Comment) <- requireJSONResponse "the response has a comment"`
2019-11-24 15:31:05 -05:00
Maximilian Tagher
b0c07ea3cd .. 2019-11-19 23:13:11 -08:00
Maximilian Tagher
cbef19fae9 [yesod-test] Add testModifySite 2019-11-19 23:11:13 -08:00
Maximilian Tagher
a2d200c182 .. 2019-11-17 12:43:24 -08:00
Maximilian Tagher
e39eaeef92 WIP - Add testModifySite 2019-11-17 12:42:20 -08:00
Maximilian Tagher
e4c493d199 .. 2019-10-09 16:11:54 -07:00
Maximilian Tagher
ffd5ba0474 Add Basic Auth support to yesod-test
This allows setting username/password for HTTP basic auth, similar to the --user flag of curl.
2019-10-09 16:08:37 -07:00
Sebastián Estrella
32ecbd056d Customize areq and wreq error message 2019-09-10 00:42:21 -05:00
Christopher League
fa90ab19ca Update changelog 2019-08-19 15:57:15 -04:00
Christopher League
08a9632eba yesod-test: correction to PR for multipart 2019-08-13 11:58:11 -04:00
Christopher League
3f98190645 Bump version to 1.6.6.2 2019-08-13 10:39:44 -04:00
Christopher League
a79f73a040 yesod-test: url-encode addPostParam keys & values
Fixes #1616
2019-08-13 10:34:57 -04:00
Christopher League
ac66323394 yesod-test: failing tests for encoding errors
Related to issue #1616
2019-08-13 10:29:21 -04:00
Michael Snoyman
006fa6cb9e
Update ChangeLog 2019-04-30 11:33:32 +03:00
Michael Snoyman
3b58652483
Compat with network 3 2019-04-30 05:13:10 +03:00
Jonathan Lamothe
6fe7ee6e0d Documentation fix (#1577)
* fixed documentation

* bumped version

* updated ChangeLog
2019-01-26 12:53:04 +05:30
Maximilian Tagher
bedec86c74 [yesod-test] Add utility functions to modify cookies 2019-01-14 16:12:32 -08:00
Dan Burton
bff8200ae4
Updated changelogs and versions for #1561 2018-10-11 14:21:17 -04:00
Dan Burton
132abccff2
Compile with ghc 8.6 by pushing MonadFail usage into IO 2018-10-11 13:53:35 -04:00
Steven Leiva
0a089c8cb0 bodyEquals prints actual body. 2018-06-14 09:00:48 -05:00
ncaq
708648798e deleted: unneed cabal build-depends by weeder
[weeder: Detect dead code](https://hackage.haskell.org/package/weeder)

deleted depends is

* mime-mail
* wai-eventsource

I sort build-depends, because duplicate depend some exist, to sort is detect to easy.
2018-06-09 13:15:21 +09:00
Tom Sydney Kerckhove
0aa1765b6c Updated according to review 2018-04-26 11:00:48 +02:00
Tom Sydney Kerckhove
a8f5418b22 yesodSpecWithSiteGenerator with an argument 2018-04-26 10:50:51 +02:00
pythonissam
860ef4127a Change the method in the example of performMethod 2018-04-14 06:47:32 +00:00
pythonissam
a9030aa294 make get and post use performMethod 2018-04-14 06:46:38 +00:00
pythonissam
7ad28d227c Update ChangeLog.md 2018-04-14 06:10:59 +00:00