我有一个像这样的vcr casette
---
http_interactions:
- request:
method: post
uri: https://control.msg91.com/api/sendotp.php?message=Your%20otp%20is%200805&mobile=919446733017&otp=0805&sender=TESTER
body:
encoding: UTF-8
string: ''
headers:
Accept-Encoding:
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept:
- "*/*"
User-Agent:
- Ruby
Host:
- control.msg91.com
Cache-Control:
- no-cache
response:
status:
code: 200
message: OK
headers:
Server:
- nginx
Date:
- Sat, 08 Jul 2017 13:54:17 GMT
Content-Type:
- text/html
Transfer-Encoding:
- chunked
Connection:
- keep-alive
Set-Cookie:
- PHPSESSID=od25ntah2t8nf47i947dmevbv0; expires=Sun, 09-Jul-2017 13:54:17 GMT;
Max-Age=86400; path=/; HttpOnly
Expires:
- Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control:
- no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma:
- no-cache
X-Frame-Options:
- SAMEORIGIN
X-Xss-Protection:
- 1; mode=block
body:
encoding: UTF-8
string: '{"message":"376768737871373032333335","type":"success"}'
http_version:
recorded_at: Sat, 08 Jul 2017 13:54:17 GMT
recorded_with: VCR 3.0.3
在uri
中,otp
和message
字段是每个请求的随机值。由于这两个是可变的(总是在变化),我如何忽略vcr中的这两个字段,以便vcr正常工作?
答案 0 :(得分:0)
看起来vcr有一个内置的解决方案。
将此添加到VCR配置块
config.default_cassette_options = {
:match_requests_on => [:method,
VCR.request_matchers.uri_without_params(:otp, :message)]
}
此处otp
和message
是我需要忽略的两件事