Inline snapshot testing was introduced by @rjchatfield in #199 as an underscored interface. It's a fantastic tool that we've used a lot, but we never got around to finalizing it with a more public interface. This PR does just that, and evolves the original helper in a few ways:
The API now follows the same structure as assertSnapshot, except it uses a trailing closure to capture the inline snapshot. This makes it easy to update an existing snapshot test to use inline snapshots:
-assertSnapshot(of: user, as: .json)
+assertInlineSnapshot(of: user, as .json)
And after recording, it looks something like this:
Trailing closures are easy to select in Xcode for deletion and re-recording.
Inline snapshots now use SwiftSyntax for inlining snapshots into Swift code. While a heavyweight dependency, it is a more reasonable tool for writing Swift code than string substitution.
Inline snapshotting is available in a separate InlineSnapshotTesting module. This is so existing snapshot tests do not need to incur the SwiftSyntax dependency.
Inline snapshotting is now extensible. It is possible to write your own inline snapshot helpers.
Inline snapshot testing was introduced by @rjchatfield in #199 as an underscored interface. It's a fantastic tool that we've used a lot, but we never got around to finalizing it with a more public interface. This PR does just that, and evolves the original helper in a few ways:
The API now follows the same structure as
assertSnapshot
, except it uses a trailing closure to capture the inline snapshot. This makes it easy to update an existing snapshot test to use inline snapshots:And after recording, it looks something like this:
Trailing closures are easy to select in Xcode for deletion and re-recording.
Inline snapshots now use SwiftSyntax for inlining snapshots into Swift code. While a heavyweight dependency, it is a more reasonable tool for writing Swift code than string substitution.
Inline snapshotting is available in a separate
InlineSnapshotTesting
module. This is so existing snapshot tests do not need to incur the SwiftSyntax dependency.Inline snapshotting is now extensible. It is possible to write your own inline snapshot helpers.