This repository was archived by the owner on Oct 2, 2025. It is now read-only.
Open
Conversation
added 7 commits
January 4, 2017 11:24
- `TimestampRecording` has been renamed to `InteractionRecording`, which now provides access to more than just the timestamp. It also includes a textual representation of each interaction as well as the file and line of occurrence. - `IntractionRecording` has been renamed to `ValueRecording`, providing chronological access to recorded interactions and their corresponding values. - The global logical clock is now thread-safe. - The recorder is now thread-safe.
If the expectation is negative and the mock is ordered (and nice), attempt to fulfill the next expectation. Fixes #38.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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,
InteractionRecordingandValueRecording. 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.