| Class | VCR::Configuration |
| In: |
lib/vcr/deprecations.rb
lib/vcr/configuration.rb |
| Parent: | Object |
Stores the VCR configuration.
| allow_http_connections_when_no_cassette | [W] |
Determines how VCR treats HTTP requests that are
made when no VCR cassette is in use. When set to
`true`, requests made when there is no VCR
cassette in use will be allowed. When set to `false` (the default), an {VCR::Errors::UnhandledHTTPRequestError}
will be raised for any HTTP request made when there is no cassette in use.
@overload allow_http_connections_when_no_cassette? @return [Boolean] whether or not HTTP connections are allowed when there is no cassette. @overload allow_http_connections_when_no_cassette= @param value [Boolean] sets whether or not to allow HTTP connections when there is no cassette. |
| debug_logger | [R] |
An object to log debug output to.
@overload debug_logger @return [#puts] the logger @overload debug_logger=(logger) @param logger [#puts] the logger @return [void] @example
VCR.configure do |c|
c.debug_logger = $stderr
end
@example
VCR.configure do |c|
c.debug_logger = File.open('vcr.log', 'w')
end
|
| default_cassette_options | [R] |
Default options to apply to every cassette.
@overload default_cassette_options @return [Hash] default options to apply to every cassette @overload default_cassette_options=(options) @param options [Hash] default options to apply to every cassette @return [void] @example
VCR.configure do |c|
c.default_cassette_options = { :record => :new_episodes }
end
@note {VCR#insert_cassette} for the list of valid options. |
| logger | [R] | @private Logger object that provides logging APIs and helper methods. |
| query_parser | [RW] |
Sets a parser for VCR to use when parsing query
strings for request comparisons. The new parser must implement a method
`call` that returns an object which is both equalivant and consistent when
given an HTTP query string of possibly differing value ordering.
The `#==` method must return true if both objects represent the same query string. This defaults to `CGI.parse` from the ruby standard library. @overload query_parser @return [#call] the current query string parser object @overload query_parser= @param value [#call] sets the query_parser |
| uri_parser | [RW] |
Sets a parser for VCR to use when parsing URIs.
The new parser must implement a
method `parse` that returns an instance of the URI object. This URI object
must implement the following interface:
The `#==` method must return true if both URI objects represent the same URI. This defaults to `URI` from the ruby standard library. @overload uri_parser @return [#parse] the current URI parser object @overload uri_parser= @param value [#parse] sets the uri_parser |
Adds a callback that will be called with each HTTP request after it is complete.
@example
VCR.configure do |c|
c.after_http_request(:ignored?) do |request, response|
puts "Request: #{request.method} #{request.uri}"
puts "Response: #{response.status.code}"
end
end
@param filters [optional splat of to_proc] one or more filters to apply.
The objects provided will be converted to procs using `#to_proc`. If provided, the callback will only be invoked if these procs all return `true`.
@yield the callback @yieldparam request [VCR::Request::Typed] the request that is being made @yieldparam response [VCR::Response] the response from the request @see before_http_request @see around_http_request
Adds a callback that will be executed around each HTTP request.
@example
VCR.configure do |c|
c.around_http_request(lambda {|r| r.uri =~ /api.geocoder.com/}) do |request|
# extract an address like "1700 E Pine St, Seattle, WA"
# from a query like "address=1700+E+Pine+St%2C+Seattle%2C+WA"
address = CGI.unescape(URI(request.uri).query.split('=').last)
VCR.use_cassette("geocoding/#{address}", &request)
end
end
@yield the callback @yieldparam request [VCR::Request::FiberAware] the request that is being made @raise [VCR::Errors::NotSupportedError] if the fiber library cannot be loaded. @param filters [optional splat of to_proc] one or more filters to apply.
The objects provided will be converted to procs using `#to_proc`. If provided, the callback will only be invoked if these procs all return `true`.
@note This method can only be used on ruby interpreters that support
fibers (i.e. 1.9+). On 1.8 you can use separate `before_http_request` and `after_http_request` hooks.
@note You must call `request.proceed` or pass the request as a proc on to a
method that yields to a block (i.e. `some_method(&request)`).
@see before_http_request @see after_http_request
Adds a callback that will be called before a previously recorded HTTP interaction is loaded for playback.
@example
VCR.configure do |c|
# Don't playback transient 5xx errors
c.before_playback do |interaction|
interaction.ignore! if interaction.response.status.code >= 500
end
# Change a response header for playback
c.before_playback(:twilio) do |interaction|
interaction.response.headers['X-Foo-Bar'] = 'Bazz'
end
end
@param tag [(optional) Symbol] Used to apply this hook to only cassettes that match
the given tag.
@yield the callback @yieldparam interaction [VCR::HTTPInteraction::HookAware] The interaction that is being
loaded.
@yieldparam cassette [(optional) VCR::Cassette] The current cassette. @see before_record
Adds a callback that will be called before the recorded HTTP interactions are serialized and written to disk.
@example
VCR.configure do |c|
# Don't record transient 5xx errors
c.before_record do |interaction|
interaction.ignore! if interaction.response.status.code >= 500
end
# Modify the response body for cassettes tagged with :twilio
c.before_record(:twilio) do |interaction|
interaction.response.body.downcase!
end
end
@param tag [(optional) Symbol] Used to apply this hook to only cassettes that match
the given tag.
@yield the callback @yieldparam interaction [VCR::HTTPInteraction::HookAware] The interaction that will be
serialized and written to disk.
@yieldparam cassette [(optional) VCR::Cassette] The current cassette. @see before_playback
Gets the directory to read cassettes from and write cassettes to.
@return [String] the directory to read cassettes from and write cassettes to
Sets the directory to read cassettes from and writes cassettes to.
@example
VCR.configure do |c|
c.cassette_library_dir = 'spec/cassettes'
end
@param dir [String] the directory to read cassettes from and write cassettes to @return [void] @note This is only necessary if you use the `:file_system`
cassette persister (the default).
Gets the registry of cassette persisters. Use it to register a custom persister.
@example
VCR.configure do |c|
c.cassette_persisters[:my_custom_persister] = my_custom_persister
end
@return [VCR::Cassette::Persisters] the cassette persister registry object. @note Custom persisters must implement the following interface:
* `persister[storage_key]` # returns previously persisted content * `persister[storage_key] = content` # persists given content
Gets the registry of cassette serializers. Use it to register a custom serializer.
@example
VCR.configure do |c|
c.cassette_serializers[:my_custom_serializer] = my_custom_serializer
end
@return [VCR::Cassette::Serializers] the cassette serializer registry object. @note Custom serializers must implement the following interface:
* `file_extension # => String` * `serialize(Hash) # => String` * `deserialize(String) # => Hash`
Sets up a {before_record} and a {before_playback} hook that will insert a placeholder string in the cassette in place of another string. You can use this as a generic way to interpolate a variable into the cassette for a unique string. It‘s particularly useful for unique sensitive strings like API keys and passwords.
@example
VCR.configure do |c|
# Put "<GITHUB_API_KEY>" in place of the actual API key in
# our cassettes so we don't have to commit to source control.
c.filter_sensitive_data('<GITHUB_API_KEY>') { GithubClient.api_key }
# Put a "<USER_ID>" placeholder variable in our cassettes tagged with
# :user_cassette since it can be different for different test runs.
c.define_cassette_placeholder('<USER_ID>', :user_cassette) { User.last.id }
end
@param placeholder [String] The placeholder string. @param tag [Symbol] Set this to apply this only to cassettes
with a matching tag; otherwise it will apply to every cassette.
@yield block that determines what string to replace @yieldparam interaction [(optional) VCR::HTTPInteraction::HookAware] the HTTP interaction @yieldreturn the string to replace
Configures which libraries VCR will hook into to intercept HTTP requests.
@example
VCR.configure do |c|
c.hook_into :fakeweb, :typhoeus
end
@param hooks [Array<Symbol>] List of libraries. Valid values are
`:fakeweb`, `:webmock`, `:typhoeus`, `:excon` and `:faraday`.
@raise [ArgumentError] when given an unsupported library name. @raise [VCR::Errors::LibraryVersionTooLowError] when the version
of a library you are using is too low for VCR to support.
@note `:fakeweb` and `:webmock` cannot both be used since they both monkey patch
`Net::HTTP`. Otherwise, you can use any combination of these.
Specifies host(s) that VCR should ignore.
@param hosts [Array<String>] List of hosts to ignore @see ignore_localhost= @see ignore_request
Sets whether or not VCR should ignore localhost requests.
@param value [Boolean] the value to set @see ignore_hosts @see ignore_request
Defines what requests to ignore using a block.
@example
VCR.configure do |c|
c.ignore_request do |request|
uri = URI(request.uri)
# ignore only localhost requests to port 7500
uri.host == 'localhost' && uri.port == 7500
end
end
@yield the callback @yieldparam request [VCR::Request] the HTTP request @yieldreturn [Boolean] whether or not to ignore the request
@return [Boolean] whether or not the body of the given HTTP message should
be base64 encoded during serialization in order to preserve the bytes exactly.
@param http_message [body, headers] the `VCR::Request` or `VCR::Response` object being serialized @see preserve_exact_body_bytes
Registers a request matcher for later use.
@example
VCR.configure do |c|
c.register_request_matcher :port do |request_1, request_2|
URI(request_1.uri).port == URI(request_2.uri).port
end
end
VCR.use_cassette("my_cassette", :match_requests_on => [:method, :host, :port]) do
# ...
end
@param name [Symbol] the name of the request matcher @yield the request matcher @yieldparam request_1 [VCR::Request] One request @yieldparam request_2 [VCR::Request] The other request @yieldreturn [Boolean] whether or not these two requests should be considered
equivalent