在 vcr 中使用可变值
Working with mutable values in vcr
我有一个像这样的录像机盒
---
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 中的这 2 个字段,以便 vcr 正常工作?
看起来 vcr 有一个内置的解决方案可用于此。
将此添加到 VCR 配置块有效
config.default_cassette_options = {
:match_requests_on => [:method,
VCR.request_matchers.uri_without_params(:otp, :message)]
}
这里otp
和message
是我需要忽略的两件事
我有一个像这样的录像机盒
---
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 中的这 2 个字段,以便 vcr 正常工作?
看起来 vcr 有一个内置的解决方案可用于此。
将此添加到 VCR 配置块有效
config.default_cassette_options = {
:match_requests_on => [:method,
VCR.request_matchers.uri_without_params(:otp, :message)]
}
这里otp
和message
是我需要忽略的两件事