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 pull request introduces several new types for recording interactions and corresponding values as well was verifying interactions with multiple recorders.
First, recording of interactions and corresponding values has been split up into two protocols,
InteractionRecording
andValueRecording
. Using protocols allows developers to define their own recorders if necessary. Dobby ships with one default, thread-safe recorder. None of the aforementioned protocols needs to deal with verification, they just need to take care of recording.Second, verification has been re-implemented using
Pattern
, which is thread-safe too. Unlike mocks, patterns can verify set up expectations with multiple interaction recorders. For example, if your test double has multiple methods, you can easily verify that they are invoked in order:Besides verification across multiple recorders, this has several other benefits. Whether expectations are strict or nice and must be fulfilled in order or not is no longer a property of the entity that records interactions. Stubs can easily act as recorders, greatly simplifying the writing of test doubles.
Under the hood, this is implemented using a thread-safe global logical clock that enables ordering interactions across multiple recorders. On verification, interactions are replayed in chronological order using a binary heap-based k-way merge iterator. Matching is based on recorder object identity and the existing matchers.
Mocks are still part of the framework, but I'm considering to remove them before we release this. Stubs haven't been extended yet.
I've had this idea in mind for quite a while, but with type-safety being one of my highest priorities, it took a while to come up with a nice solution. I think this is the future of Dobby and would appreciate collaborators and interested developers to have a look and provide feedback, thanks.