2014-02-28 2 views
1

example.com에 대한 요청이있는 모든 사양에서 요청 일치 자에 대한 URI의 후행 ID를 무시하고 싶습니다. 이 같은. 당신이 아니라 사람이 example.com 일치의 설정을 변경 한 후 만든 모든 요청에 영향을 미칠 것이기 때문에 before_http_request의 글로벌 구성을 수정요청 URI를 기반으로 VCR의 기본 옵션을 설정합니다.

VCR.configure do |c| 
    # omitted 
    c.register_request_matcher :uri_ignoring_trailing_id do |request_1, request_2| 
    # omitted 
    end 

    c.before_http_request(lambda { |req| req.uri =~ /example.com/ }) do 
    c.default_cassette_options = { match_requests_on: [ :uri_ignoring_trailing_id ] } 
    end 

end 

답변

5

나쁜 생각이다. 대신 다음과 같이하는 것이 좋습니다.

VCR.configure do |vcr| 
    uri_matcher = VCR.request_matchers[:uri] 
    vcr.register_request_matcher(:uri_ignoring_trailing_id_for_example_dot_com) do |req_1, req_2| 
    if req_1.parsed_uri.host == "example.com" && req_2.parsed_uri.host == "example.com" 
     # do your custom matching where you ignore trailing id 
    else 
     uri_matcher.matches?(req_1, req_2) 
    end 
    end 

    vcr.default_cassette_options = { match_requests_on: [:method, :uri_ignoring_trailing_id_for_example_dot_com] } 
end 
관련 문제