From f414e04f49b7544b40a1727bc5bd2a7ccc823cff Mon Sep 17 00:00:00 2001 From: Arthur Hamon Date: Thu, 13 Jun 2019 15:14:11 +0200 Subject: [PATCH] update the documentation of custom matchers Add documentation on creating a matcher with an `assert` statement that provides assertion messages in case of failures. --- docs/advanced.rst | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/advanced.rst b/docs/advanced.rst index 198a3d2..ed5aa08 100644 --- a/docs/advanced.rst +++ b/docs/advanced.rst @@ -97,8 +97,12 @@ Create your own method with the following signature def my_matcher(r1, r2): -Your method receives the two requests and must return ``True`` if they -match, ``False`` if they don't. +Your method receives the two requests and can return : + +- Use an ``assert`` statement in the matcher, then we have ``None`` if they match, raise an `AssertionError`` if they don't. +- A boolean, ``True`` if they match, ``False`` if they don't. + +Note : You should use an ``assert`` statement in order to have feedback when a matcher is failing. Finally, register your method with VCR to use your new request matcher. @@ -107,7 +111,7 @@ Finally, register your method with VCR to use your new request matcher. import vcr def jurassic_matcher(r1, r2): - return r1.uri == r2.uri and 'JURASSIC PARK' in r1.body + assert r1.uri == r2.uri and 'JURASSIC PARK' in r1.body my_vcr = vcr.VCR() my_vcr.register_matcher('jurassic', jurassic_matcher)