diff --git a/CHANGELOG.md b/CHANGELOG.md index 364a3ee..5be2216 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/main/java/com/easypost/easyvcr/MatchRules.java b/src/main/java/com/easypost/easyvcr/MatchRules.java index 0c9c0f0..248090a 100644 --- a/src/main/java/com/easypost/easyvcr/MatchRules.java +++ b/src/main/java/com/easypost/easyvcr/MatchRules.java @@ -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 rule) { + by(rule); + return this; + } + /** * Execute rules to determine if the received request matches the recorded request. *