2013-07-23 3 views
1

내 사양이 master 분기로 전달됩니다. 새 분기를 만들고 구독과 관련이없는 코드를 완전히 수정하면 실패 할 것입니다. 내가 그들을 통과시킬 수있는 유일한 방법은 내 vcr.rb가 :record => :new_episodes이되도록 변경하는 것입니다.VCR 처리되지 않은 http 요청 오류

이 옵션을 켜 놓으면 거의 언제나 내 사양이 실행될 때마다 Git 로그를 희석시키는 커밋 된 카세트에 대한 새로운 수정 된 데이터 파일이 생깁니다.

이 문제를 해결하는 방법에 대한 제안 사항이 있으십니까? 깨는 많은 사양은이 정규식을 기반으로합니다.

describe "#change_plan_to", vcr: {match_requests_on: [:method, :uri, :body]} do 

이 정규 표현식을 너무 열어서 변경할 수 있습니까? 스트라이프 API 호출로 스펙을 다른 방법으로 전달할 수 없었습니다.

Failure/Error: @subscription.create_stripe_customer 
    VCR::Errors::UnhandledHTTPRequestError: 


     ================================================================================ 
     An HTTP request has been made that VCR does not know how to handle: 
     POST https://api.stripe.com/v1/customers 

     VCR is currently using the following cassette: 
     - /Users/app/spec/data/Subscription/_change_plan_to/stripe_customer_subscription_plan_/name/.json 
     - :record => :once 
     - :match_requests_on => [:method, :uri, :body] 

     Under the current configuration VCR can not find a suitable HTTP interaction 
     to replay and is prevented from recording new requests. There are a few ways 
     you can deal with this: 

     * If you're surprised VCR is raising this error 
      and want insight about how VCR attempted to handle the request, 
      you can use the debug_logger configuration option to log more details [1]. 
     * You can use the :new_episodes record mode to allow VCR to 
      record this new request to the existing cassette [2]. 
     * If you want VCR to ignore this request (and others like it), you can 
      set an `ignore_request` callback [3]. 
     * The current record mode (:once) does not allow new requests to be recorded 
      to a previously recorded cassette. You can delete the cassette file and re-run 
      your tests to allow the cassette to be recorded with this request [4]. 
     * The cassette contains 109 HTTP interactions that have not been 
      played back. If your request is non-deterministic, you may need to 
      change your :match_requests_on cassette option to be more lenient 
      or use a custom request matcher to allow it to match [5]. 

     [1] https://www.relishapp.com/vcr/vcr/v/2-5-0/docs/configuration/debug-logging 
     [2] https://www.relishapp.com/vcr/vcr/v/2-5-0/docs/record-modes/new-episodes 
     [3] https://www.relishapp.com/vcr/vcr/v/2-5-0/docs/configuration/ignore-request 
     [4] https://www.relishapp.com/vcr/vcr/v/2-5-0/docs/record-modes/once 
     [5] https://www.relishapp.com/vcr/vcr/v/2-5-0/docs/request-matching 
     ================================================================================ 
    # ./app/models/subscription.rb:83:in `create_stripe_customer' 
    # ./spec/models/subscription_spec.rb:68:in `block (3 levels) in <top (required)>' 
    # -e:1:in `<main>' 

좀 더 알아 냈습니다. 스펙은 새 스펙을 스택에 추가 할 때만 중단됩니다. 더 많은 것들이 스위트에 추가되면 어떻게 깨지나요?

답변

4

표시되는 동작은 요청을 일치시키는 데 사용되는 특성 중 하나가 비 결정적이며 테스트를 실행할 때마다 변경된다는 것을 나타냅니다. 당신은 match_requests_on: [:method, :uri, :body] 옵션을 사용하여 언급 - 난 그게 body 같아요. VCR에 내장 된 본문 일치 프로그램은 직접 body_string == body_string 비교를 수행하므로 시체가 의미 상 동일하지만 동일한 문자열이 아닌 상황을 쉽게 파악할 수 있습니다. 예를 들어 {"a": 1", "b": 2}{"b": 2, "a": 1} 같은 JSON 문자열을 예로들 수 있습니다.

제안 사항 : body과 일치하지 않는 경우가 있습니다. 특정 상황에서 필요하다면 거기에 있습니다.하지만 더 조심스럽게 일치하는 경우 VCR은 HTTP 상호 작용을 원래 발생한 순서대로 기록하므로 정상적으로 작동합니다. 재생 중에는 사용하지 않은 첫 번째 상호 작용을 재생합니다. 테스트에서 원래 순서대로 요청을하면 각 요청에 대해 올바른 응답이 재생됩니다.

정확히 무슨 일이 일어나는지 더 자세히 알기 위해 일치하는 내용을 상세하게 출력하고 수행하는 이유를 보여주는 debug logger 옵션을 사용할 수 있습니다.

+0

통찰력있는 답변을 보내 주셔서 감사합니다. 내가 시체를 제거하면 스펙은 통과하지 못한다. 어떻게 처리 할 것인가? 디버거를 켜고 내가 본 것에 붙여 넣을 것입니다. –

+0

다음과 같은 오류가 있습니다. https://gist.github.com/anonymous/0661a0e821ae907de0e3 및 spec : https://gist.github.com/anonymous/588697967840ee97317f –

+0

이전에 대해 읽었으므로 여전히 실패합니다 : https://gist.github.com/anonymous/672bf704fd7ae3aec989 –

관련 문제