github maxbrunsfeld/counterfeiter v6.14.0

7 hours ago

This release has two additions to the fake API for reading back what a fake was called with, a fix for a race in methods without return values, and a guide for anyone coming from gomock.

Inspecting calls

  • ๐Ÿ†• <Method>Args() returns every call to a method as a slice of structs, with one exported field per argument: FakeMySpecialInterfaceDoThingsArgs{Arg1: "stuff", Arg2: 5}. You can check a whole call with one Equal or cmp.Diff, and skip an argument with cmpopts.IgnoreFields. Function fakes get the same thing as Args(). ArgsForCall still works as before. @dnephin asked for this in 2018. (#392, fixes #106)
  • ๐Ÿ†• CallOrder() returns the names of a fake's methods in the order they were called, so you can assert that, for example, Write() was called before Commit(). Order across two fakes still isn't recorded; the gomock guide has a stub recipe for that. (#394, fixes #113)

Fixes

  • ๐Ÿ› A method with no return values called its stub field again after unlocking, instead of the copy it took under the lock. Swapping the stub from another goroutine at that moment was a data race, and Calls(nil) could panic the caller. Both templates call the copy now. (#389)

๐Ÿ“– Docs

  • docs/migrating-from-gomock.md maps gomock's controller, expectations, matchers, call counts and ordering onto a fake's Returns, Calls, ArgsForCall, CallCount, Args and CallOrder, with the same check shown in testing, testify and gomega.

๐Ÿงน Housekeeping

  • โฌ†๏ธ gomega 1.43.1 (#391). go-cmp is a direct dependency now because a spec imports it; it was already in go.mod through gomega, and a module that has counterfeiter as a tool sees no change.
  • โฌ†๏ธ CodeQL actions
  • the one table test in the generator package is a spec suite like the rest (#393)

Regenerating produces a diff in every fake: the per-method record is the new struct type, and the fake keeps the call order.

Full Changelog: v6.13.0...v6.14.0

Don't miss a new counterfeiter release

NewReleases is sending notifications on new releases.