Merged
Conversation
Member
Author
|
After looking at usage a little more, the middleware parameter should probably be: given that that's how the yesod scaffold generates it: https://github.com/yesodweb/yesod-scaffold/blob/3378e25e54472b7ea9f691b460ff46e9f9e8382c/test/TestImport.hs#L44 |
Member
|
Seems reasonable 👍 |
Member
Author
|
Awesome, ready for review 👍 |
snoyberg
approved these changes
Nov 20, 2019
Member
snoyberg
left a comment
There was a problem hiding this comment.
Thanks! This is good to merge and release once CI passes. Want to do the merge/release, or should I?
Member
Author
|
I can take it |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is a draft to propose a new functiontestModifySiteIn most Yesod apps, there is an
Appdatatype at the core of the application, holding all configuration and state for the app (e.g. settings, connection pools,IORefs, etc.). In the tests, this is setup on a per-test basis. This PR adds a new function,testModifySite, to modify that site in the middle of a test. This is the signature:Here are some use cases I'm imagining:
Testing how modifying settings changes behavior
The yesod scaffold comes with an
AppSettingstype you use to configure your app. An app may want to have a test like so:Changing out stubbed functions
The use case we have at work is we have a
Stubsdatatype in our app, and we use it to stub out functions. This looks roughly like so:And in production, we set
stubMailerHandlerSendEmailtoNothing, in which case our codebase uses the production implementation, but in tests we can use the stubbed function to customize behavior.testModifySitewould allow us to modify that stub in the middle of a test, so we could have tests like this:A gotcha about this function is that the
yedSiteandyedAppparameters are tied together. So, once the site is modified, a newyedAppmust be created from it usingtoWaiAppPlainthen calling a new middleware function. I think this is OK though?One could maybe drop the
Middlewareparameter oftestModifySite, but theMiddlewareinitially provided would have to be stored inYesodExampleDatafor later, which would be a breaking change. Also, it adds complexity toYesodExampleDatajust for the convenience of this function.If this function sounds good, I'll add another function called
testSetSitethat outright replaces the site value.