在VCR

2017-07-08 70 views
0

與可變值工作,我有這樣的在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 

錄像機卡式在uriotpmessage領域這是每個請求的隨機值。由於這兩個是可變的(總是變化)我怎麼能忽略這兩個字段在vcr中,使vcr工作正常?

回答

0

看起來像vcr有一個內置的解決方案可用於此。

添加此到VCR配置塊工作

config.default_cassette_options = { 
     :match_requests_on => [:method, 
          VCR.request_matchers.uri_without_params(:otp, :message)] 
    } 

這裏otpmessage是兩件事情,我需要忽略