-
-
Notifications
You must be signed in to change notification settings - Fork 905
Updated TestState to remove the value after the test. #1240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
younata
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! Really appreciate it.
Also, would you like commit privileges to Quick and Nimble? You've been doing some great work, and I'd like to invite you to the Quick team.
I could take it, though I probably wouldn't do much with it until I felt more comfortable with the repo. |
younata
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about the delay. This looks great, though. Thanks for doing this!
This PR contains the following updates: | Package | Update | Change | |---|---|---| | [Quick/Quick](https://togithub.com/Quick/Quick) | minor | `from: "7.2.0"` -> `from: "7.3.0"` | --- ### Release Notes <details> <summary>Quick/Quick (Quick/Quick)</summary> ### [`v7.3.0`](https://togithub.com/Quick/Quick/releases/tag/v7.3.0) [Compare Source](https://togithub.com/Quick/Quick/compare/v7.2.0...v7.3.0) #### Highlights - Adds a property wrapper default initializer for TestState. Meaning the following declaration is now accepted! ```swift @​TestState var foo: Int! = 30 ``` Thanks [@​tahirmt](https://togithub.com/tahirmt)! - TestState now nils out the value after all afterEach blocks run, instead of in the middle of the afterEach chain. Thanks [@​CraigSiemens](https://togithub.com/CraigSiemens) #### What's Changed - Bump activesupport from 7.0.4.3 to 7.0.7.2 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/Quick/Quick/pull/1238](https://togithub.com/Quick/Quick/pull/1238) - Add property wrapper default initializer for TestState by [@​tahirmt](https://togithub.com/tahirmt) in [https://github.com/Quick/Quick/pull/1235](https://togithub.com/Quick/Quick/pull/1235) - Bump actions/checkout from 3 to 4 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/Quick/Quick/pull/1241](https://togithub.com/Quick/Quick/pull/1241) - Updated TestState to remove the value after the test. by [@​CraigSiemens](https://togithub.com/CraigSiemens) in [https://github.com/Quick/Quick/pull/1240](https://togithub.com/Quick/Quick/pull/1240) - Update release script to generate a carthage binary and include it in the release. by [@​younata](https://togithub.com/younata) in [https://github.com/Quick/Quick/pull/1234](https://togithub.com/Quick/Quick/pull/1234) #### New Contributors - [@​tahirmt](https://togithub.com/tahirmt) made their first contribution in [https://github.com/Quick/Quick/pull/1235](https://togithub.com/Quick/Quick/pull/1235) **Full Changelog**: Quick/Quick@v7.2.0...v7.3.0 </details> --- ### Configuration π **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). π¦ **Automerge**: Enabled. β» **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. π» **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://togithub.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://togithub.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi45Ni4wIiwidXBkYXRlZEluVmVyIjoiMzYuOTYuMCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Co-authored-by: Self-hosted Renovate Bot <361546+cgrindel-self-hosted-renovate[bot]@users.noreply.github.enterprise.com>
Currently, a property with
@TestStatewill have its value reset tonilbefore anyafterEachin the sameExampleGroupis run. This is because:@TestStateneeds to be defined first so the tests can use it@TestStatewas adding anafterEachto the currentExampleGroupafterEachclosures are run in the order they are defined in anExampleGroupThis causes the
afterEachresetting theTestStatevalue to always be run before theafterEachclosures defined in the sameExampleGroup.This is an issue when a test needs to do additional cleanup using the value from
TestState. Ideally the value in theTestState` would only be cleaned up after all the code in the test has finished running.Example
When this runs, the
afterEachwill crash becausetempDirhas already been reset to nil.Solution
TestStatehas been updated to use anafterEachset in aQuickConfigurationto ensure that the value is reset after the current example group has finished running. This works because configurations behave like a parentExampleGroupof the rootExampleGroupfor the spec.On one hand this does feel a little wierd to for Quick itself to be defining a configuration, but it was the simplest approach I could find.It's been updated to add a teardown block to the test case to set the value back to nil since that will always be run after the
afterEachblocks.Alternatives considered
Update
ExampleGroup/ExampleHooksto aalwaysAfterEacharray that would function similar tojustBeforeEachwhere it's a second array of closures that are always run last. This would have been a larger change to add support to the Sync/Async versions ofWorld,ExampleGroup, andExampleHooksChecklist