-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preview: Introducing patterns #40
Open
felixvisee
wants to merge
12
commits into
master
Choose a base branch
from
behavior
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains 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
- `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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.