2014-09-12 3 views
3

VCR을 설정하고 문제없이 작성한 몇 가지 테스트를 실행합니다. 필자가 작성한 가장 최근의 테스트는 처음 실행될 때 통과 할 것이지만 카세트를 삭제하지 않으면 그 후에도 실패 할 것입니다. 테스트를위한 코드는 다음과 같습니다VCR 던지기 cant는 두 번째 시도 시도 테스트 (첫 번째 시도 통과)에 대한 요청을 처리합니다.

장애/오류 : 다음과 같이

it "doesn't blow up if a user doesn't have billing info" do 
    VCR.use_cassette('tax_reconciler/no_method_error')do 
     user_guid = rand(10000000) 
     CreateRecurlyTestData.create_account(user_guid, nil, nil) 
     tax_reconciler = TaxReconciler.new 
     new_tax_amount = rand(100000) 
     user = create_test_user(:guid => user_guid) 
     expect(tax_reconciler.update_tax_amount(user, new_tax_amount)).to_not raise_error 
    end 
    end 

오류 메시지가 CreateRecurlyTestData.create_account (user_guid, 전무, 전무)을 VCR :: 오류 :: UnhandledHTTPRequestError :

사양 도우미에서
================================================================================ 
    An HTTP request has been made that VCR does not know how to handle: 
    GET https://2b64d08ef45c446dbba75720a37b7d41:@api.recurly.com/v2/accounts/3276643 

    VCR is currently using the following cassette: 
    - /Users/Evan/dish/stallone/fixtures/vcr_cassettes/tax_reconciler/no_method_error.yml 
    - :record => :once 
    - :match_requests_on => [:method, :uri] 

    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 4 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-9-3/docs/configuration/debug-logging 
    [2] https://www.relishapp.com/vcr/vcr/v/2-9-3/docs/record-modes/new-episodes 
    [3] https://www.relishapp.com/vcr/vcr/v/2-9-3/docs/configuration/ignore-request 
    [4] https://www.relishapp.com/vcr/vcr/v/2-9-3/docs/record-modes/once 
    [5] https://www.relishapp.com/vcr/vcr/v/2-9-3/docs/request-matching 

유일한 설정 옵션은 다음과 같습니다

VCR.configure do |c| 
    c.cassette_library_dir = 'fixtures/vcr_cassettes' 
    c.hook_into :webmock # or :fakeweb 
    end 
+1

기본적으로 vcr ('vcr/vcr.rb') 소스 코드를 붙여 넣었습니다. 일반적으로 이것은 구성에 의한 것이 아닙니다. 이상한 재정의 일을하고 있니? 또한 : 실제 오류를 게시하십시오. 나는 당신이 잘못된 녹음 모드를 사용하고있는 것처럼 들린다 고 생각합니다. – Jesper

+0

오류 메시지와 구성을 업데이트했습니다. 내 사과하지만 이전에 붙여 넣은 설정은 설정이라고 생각했습니다. 내 사용자 이름이 여기에 적용됩니다. 다시 한번 감사드립니다. –

답변

4

VCR 설정이 녹화 모드로 구성되었습니다. :once : https://www.relishapp.com/vcr/vcr/v/1-8-0/docs/record-modes/once

요약하면 카세트가 없을 때만 요청을 기록합니다. 후속 실행의 경우 기록 된 요청 만 읽으므로 기록 된 요청과 일치하지 않는 요청은이 오류를 발생시킵니다.

이 모드에서 일이 잘못되는 일반적인 방법 중 하나는 카세트를 삭제하고 전체 제품군 대신 하나의 사양 만 실행하는 것입니다. Bingo - 귀하의 카세트가 생성되고 해당 특정 사양의 것을 제외한 모든 요청이 인식되지 않습니다.

이 모드의 위 쪽은 위조 된 요청을 포착 할 수 있다는 것입니다. 카세트에 모든 유효한 요청이 포함되어 있으면이 모드를 사용하여 잘못된 요청으로 인한 버그를 잡을 수 있습니다.

유연성을 높이려면 녹음 모드 new_episodes을 사용할 수 있습니다. 이 모드에서는 인식 된 요청이 카세트에서 재생되고 다시 계산되지 않은 요청이 수행되고 녹음됩니다.

+0

비슷한 문제가있는 사람들에게이 문제를 해결 한 행은 "VCR.use_cassette ('tax_reconciler/no_method_error', : record => : new_episodes)"입니다. 여러분 모두를 도와 주셔서 감사합니다. –

+3

': record => : new_episodes'를 추가하면 오류를 우회하지만 아마도 원하는 것이 아닙니다. VCR을 사용하여 빠르고 결정 론적 인 테스트를하고 있지만': record => : new_episodes'는 VCR이 일치하는 요청을 찾지 못하면 요청을 허용하고 기록합니다. 새 요청을 트리거하는 코드를 변경 한 경우라면 문제가 없지만 테스트를 다시 실행할 때 발생하는 것처럼 들리는 경우가 있습니다. VCR은 이전 테스트와 비교할 수 없습니다. 요청이 비 결정적이기 때문일 수 있습니다. 각 테스트 실행시 '2b64d08ef45c446dbba75720a37b7d41'과 '3276643' 파트가 동일합니까? –

관련 문제