Search code examples
apiunit-testingvcr

Custom Request Matcher for SEOMOZ + VCR


I am trying to integrate SEOMOZ API with VCR.

As the API request to SEOMOZ contains parameters that change for the same request over time, I need to implement a custom matcher.

Here is what my API call looks like :

http://lsapi.seomoz.com/linkscape/url-metrics/#{self.url}?Cols=#{cols}&AccessID=#{moz_id}&Expires=#{expires}&Signature=#{url_safe_signature} 

I also make calls to other endpoints such as Twitter,Facebook etc etc. For which the default matcher does the job well.

How can I override the matcher behavior just for SEOMOZ. Also on what parameters should I best match the request in this case.


Solution

  • You'll want to match on all parameters except Signature and Expires.

    Another option you might consider (we use it internally when using VCR with this sort of API) is to record the time of the test in a file with the cassettes, and use Timecop or something equivalent to ensure you're re-running the recorded test at the "same time" every time you run it.