Skip to content

Commit

Permalink
Return Test from Test.Expect().
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed Dec 20, 2020
1 parent 45c9b6f commit e986e10
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The format is based on [Keep a Changelog], and this project adheres to
[Keep a Changelog]: https://keepachangelog.com/en/1.0.0/
[Semantic Versioning]: https://semver.org/spec/v2.0.0.html

## [Unreleased]
## [0.12.0] - 2020-12-20

This release includes several changes to the underlying action and expectation
systems, some of which are not backwards compatable. Tests written using v0.11.0
Expand All @@ -23,6 +23,7 @@ should continue to work without modification.
### Changed

- **[BC]** Renamed `Action.Apply()` to `Do()`
- `Test.Expect()` now returns the `Test`, allowing chained calls

### Removed

Expand Down Expand Up @@ -243,6 +244,7 @@ simple to migrate existing tests to the new API. Please see the
[0.9.0]: https://github.com/dogmatiq/testkit/releases/tag/v0.9.0
[0.10.0]: https://github.com/dogmatiq/testkit/releases/tag/v0.10.0
[0.11.0]: https://github.com/dogmatiq/testkit/releases/tag/v0.11.0
[0.12.0]: https://github.com/dogmatiq/testkit/releases/tag/v0.12.0

[v0.11.0 migration guide]: https://github.com/dogmatiq/testkit/blob/main/docs/MIGRATING-v0.11.0.md

Expand Down
8 changes: 5 additions & 3 deletions test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (t *Test) Prepare(actions ...Action) *Test {
}

// Expect ensures that a single action results in some expected behavior.
func (t *Test) Expect(act Action, e Expectation) {
func (t *Test) Expect(act Action, e Expectation) *Test {
t.testingT.Helper()

s := PredicateScope{App: t.app}
Expand All @@ -102,7 +102,7 @@ func (t *Test) Expect(act Action, e Expectation) {
p, err := e.Predicate(s)
if err != nil {
t.testingT.Fatal(err)
return // required when using a mock testingT that does not panic
return t // required when using a mock testingT that does not panic
}

// Using a defer inside a closure satisfies the requirements of the
Expand All @@ -114,7 +114,7 @@ func (t *Test) Expect(act Action, e Expectation) {
return t.doAction(act, engine.WithObserver(p))
}(); err != nil {
t.testingT.Fatal(err)
return // required when using a mock testingT that does not panic
return t // required when using a mock testingT that does not panic
}

treeOk := p.Ok()
Expand All @@ -128,6 +128,8 @@ func (t *Test) Expect(act Action, e Expectation) {
if !treeOk {
t.testingT.FailNow()
}

return t
}

// CommandExecutor returns a dogma.CommandExecutor which can be used to execute
Expand Down

0 comments on commit e986e10

Please sign in to comment.