> For the complete documentation index, see [llms.txt](https://andrewmcodes.gitbook.io/vcr/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://andrewmcodes.gitbook.io/vcr/request_matching/playback_repeats.md).

# Playback repeats

By default, each response in a cassette can only be matched and played back once while the cassette is in use (it can, of course, be re-used in multiple tests, each of which should use the cassette separately). Note that this is a change from the behavior in VCR 1.x. The old behavior occurred because of how WebMock behave internally and was not intended. Repeats create less accurate tests since the real HTTP server may not necessarily return the same response when identical requests are made in sequence.

If you want to allow playback repeats, VCR has a cassette option for this:

```
  :allow_playback_repeats => true
```

## Responses do not repeat by default

*Given* a previously recorded cassette file "cassettes/example.yml" with:

```
--- 
http_interactions: 
- request: 
    method: get
    uri: http://example.com/foo
    body: 
      encoding: UTF-8
      string: ""
    headers: {}
  response: 
    status: 
      code: 200
      message: OK
    headers: 
      Content-Length: 
      - "10"
    body: 
      encoding: UTF-8
      string: Response 1
    http_version: "1.1"
  recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
- request: 
    method: get
    uri: http://example.com/foo
    body: 
      encoding: UTF-8
      string: ""
    headers: {}
  response: 
    status: 
      code: 200
      message: OK
    headers: 
      Content-Length: 
      - "10"
    body: 
      encoding: UTF-8
      string: Response 2
    http_version: "1.1"
  recorded_at: Tue, 01 Nov 2011 04:58:44 GMT
recorded_with: VCR 2.0.0
```

*And* a file named "playback\_repeats.rb" with:

```
include_http_adapter_for("net/http")

require 'vcr'

VCR.configure do |c|
  c.hook_into :webmock
  c.cassette_library_dir = 'cassettes'
end

puts "== With :allow_playback_repeats =="
VCR.use_cassette('example', :allow_playback_repeats => true) do
  puts response_body_for(:get, 'http://example.com/foo')
  puts response_body_for(:get, 'http://example.com/foo')
  puts response_body_for(:get, 'http://example.com/foo')
end

puts "\n== Without :allow_playback_repeats =="
VCR.use_cassette('example') do
  puts response_body_for(:get, 'http://example.com/foo')
  puts response_body_for(:get, 'http://example.com/foo')
  puts response_body_for(:get, 'http://example.com/foo')
end
```

*When* I run `ruby playback_repeats.rb`

*Then* it should fail with "An HTTP request has been made that VCR does not know how to handle"

*And* the output should contain:

```
== With :allow_playback_repeats ==
Response 1
Response 2
Response 2

== Without :allow_playback_repeats ==
Response 1
Response 2
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://andrewmcodes.gitbook.io/vcr/request_matching/playback_repeats.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
