Skip to content

Commit

Permalink
- Add ability for users to define their own match rule(s) (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
nwithan8 committed May 18, 2023
1 parent 95e3801 commit a6fdfac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next Release

- New `byCustomRule` function to allow users to define their own matching rule when finding a matching interaction in a cassette
- Improve error messages when a matching interaction is not found (human-readable error messages)
- Fix bug where the base URL matching rule was not comparing the scheme, host, and port of the request URL properly

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/easypost/easyvcr/MatchRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,18 @@ public MatchRules byMethod() {
return this;
}

/**
* Add a rule to compare two requests by a custom rule.
* @param rule A BiFunction that accepts two Request instances and returns true if they match, false otherwise.
* The first parameter is the current in-flight request,
* the second parameter is the recorded request from the current cassette.
* @return This MatchRules factory.
*/
public MatchRules byCustomRule(BiFunction<Request, Request, Boolean> rule) {
by(rule);
return this;
}

/**
* Execute rules to determine if the received request matches the recorded request.
*
Expand Down

0 comments on commit a6fdfac

Please sign in to comment.