如何使用webmock正则表达式匹配器?
如何匹配以下url:
http://www.example.com/foo/:id/bar http://www.example.com/foo/1/bar http://www.example.com/foo/999/bar
stub_request(:post,“www.example.com”)
http://www\..*?\.com/foo/\d+/bar
应该适合你。
对于Ruby中的正则表达式,可以使用%r{}
而不是//
来避免必须转义URL中的正斜杠。 例如:
stub_request(:post, %r{\Ahttp://www.example.com/foo/\d+/bar\z})
stub_request的第二个参数必须是正则表达式,而不是字符串。
stub_request(:post, /http:\/\/www.example.com\/foo\/\d+\/bar/)