B S*_*ven 24 ruby regex rspec webmock
如何匹配以下URL:
http://www.example.com/foo/:id/bar
http://www.example.com/foo/1/bar
http://www.example.com/foo/999/bar
Run Code Online (Sandbox Code Playgroud)
stub_request(:post,"www.example.com")
Ger*_*haw 27
您可以在Ruby中使用%r{}
而不是//
正则表达式来避免必须转义URL中的正斜杠.例如:
stub_request(:post, %r{\Ahttp://www.example.com/foo/\d+/bar\z})
Run Code Online (Sandbox Code Playgroud)
Phi*_*thé 17
stub_request的第二个参数必须是正则表达式,而不是字符串.
stub_request(:post, /http:\/\/www.example.com\/foo\/\d+\/bar/)
Run Code Online (Sandbox Code Playgroud)
Jac*_*ack 12
http://www\..*?\.com/foo/\d+/bar
应该适合你.