ruby-on-railsrspecstubwebmock

How to use webmock with an address that has a variable?


I am using the webmock gem to stub requests for rspec tests.

One of my requests makes a request to a microservice that includes a type and a timestamp in the address:

e.g. www.microservice.com/type=1?timestamp=1521493200

I can stub the type easily, but I cannot stub the timestamp because it constantly changes based on the code. How can I stub this request?


Solution

  • You can use a regular expression e.g. stub_request(:get, /www.microservice.com\/type=1\?timestamp=\d+/)