Module: VCR
- Extended by:
- VCR
- Includes:
- Errors, VariableArgsBlockCaller
- Included in:
- VCR
- Defined in:
- lib/vcr.rb,
lib/vcr/errors.rb,
lib/vcr/structs.rb,
lib/vcr/version.rb,
lib/vcr/cassette.rb,
lib/vcr/util/hooks.rb,
lib/vcr/util/logger.rb,
lib/vcr/deprecations.rb,
lib/vcr/configuration.rb,
lib/vcr/library_hooks.rb,
lib/vcr/middleware/rack.rb,
lib/vcr/request_handler.rb,
lib/vcr/request_ignorer.rb,
lib/vcr/middleware/excon.rb,
lib/vcr/cassette/migrator.rb,
lib/vcr/middleware/faraday.rb,
lib/vcr/cassette/persisters.rb,
lib/vcr/library_hooks/excon.rb,
lib/vcr/cassette/serializers.rb,
lib/vcr/util/version_checker.rb,
lib/vcr/cassette/erb_renderer.rb,
lib/vcr/library_hooks/fakeweb.rb,
lib/vcr/library_hooks/faraday.rb,
lib/vcr/library_hooks/webmock.rb,
lib/vcr/test_frameworks/rspec.rb,
lib/vcr/library_hooks/typhoeus.rb,
lib/vcr/request_matcher_registry.rb,
lib/vcr/test_frameworks/cucumber.rb,
lib/vcr/util/internet_connection.rb,
lib/vcr/cassette/serializers/json.rb,
lib/vcr/cassette/serializers/syck.rb,
lib/vcr/cassette/serializers/yaml.rb,
lib/vcr/cassette/serializers/psych.rb,
lib/vcr/library_hooks/typhoeus_0.4.rb,
lib/vcr/extensions/net_http_response.rb,
lib/vcr/cassette/http_interaction_list.rb,
lib/vcr/cassette/persisters/file_system.rb,
lib/vcr/cassette/serializers/compressed.rb,
lib/vcr/middleware/excon/legacy_methods.rb,
lib/vcr/util/variable_args_block_caller.rb
Overview
This module is extended onto itself; thus, the methods listed here as instance methods are available directly off of VCR.
The main entry point for VCR.
Defined Under Namespace
Modules: Deprecations, Errors, Hooks, InternetConnection, Middleware, Net, Normalizers, OrderedHashSerializer, RSpec, VariableArgsBlockCaller Classes: Cassette, Configuration, CucumberTags, HTTPInteraction, LibraryHooks, Logger, Request, RequestHandler, RequestIgnorer, RequestMatcherRegistry, Response, ResponseStatus, VersionChecker
Constant Summary collapse
- CassetteMutex =
Mutex to synchronize access to cassettes in a threaded environment
Mutex.new
- MainThread =
The main thread in which VCR was loaded
Thread.current
Class Method Summary collapse
Instance Method Summary collapse
- #cassette_persisters ⇒ Object
- #cassette_serializers ⇒ Object
-
#config ⇒ Object
deprecated
Deprecated.
Use #configure instead.
-
#configuration ⇒ VCR::Configuration
The VCR configuration.
-
#configure {|config| ... } ⇒ void
Used to configure VCR.
-
#cucumber_tags {|t| ... } ⇒ void
Sets up ‘Before` and `After` cucumber hooks in order to use VCR with particular cucumber tags.
-
#current_cassette ⇒ nil, VCR::Cassette
The currently active cassette.
-
#eject_cassette(options = {}) ⇒ VCR::Cassette?
Ejects the current cassette.
- #fibers_available? ⇒ Boolean
- #http_interactions ⇒ Object
-
#insert_cassette(name, options = {}) ⇒ VCR::Cassette
Inserts the named cassette using the given cassette options.
- #library_hooks ⇒ Object
- #link_context(from_thread, to_key) ⇒ Object
- #real_http_connections_allowed? ⇒ Boolean
- #record_http_interaction(interaction) ⇒ Object
- #request_ignorer ⇒ Object
-
#request_matchers ⇒ RequestMatcherRegistry
The request matcher registry.
-
#turn_off!(options = {}) ⇒ void
Turns VCR off, so that it no longer handles every HTTP request.
-
#turn_on! ⇒ void
Turns on VCR, if it has previously been turned off.
-
#turned_off(options = {}) ⇒ void
Turns VCR off for the duration of a block.
-
#turned_on? ⇒ Boolean
Whether or not VCR is turned on.
- #unlink_context(key) ⇒ Object
-
#use_cassette(name, options = {}) {|cassette| ... } ⇒ void
Inserts a cassette using the given name and options, runs the given block, and ejects the cassette.
-
#version ⇒ String
The current VCR version.
Methods included from VariableArgsBlockCaller
Class Method Details
.const_missing(const) ⇒ Object
10 11 12 13 14 |
# File 'lib/vcr/deprecations.rb', line 10 def self.const_missing(const) return super unless const == :Config warn "WARNING: `VCR::Config` is deprecated. Use VCR.configuration instead." configuration end |
Instance Method Details
#cassette_persisters ⇒ Object
326 327 328 |
# File 'lib/vcr.rb', line 326 def cassette_persisters @cassette_persisters end |
#cassette_serializers ⇒ Object
321 322 323 |
# File 'lib/vcr.rb', line 321 def cassette_serializers @cassette_serializers end |
#config ⇒ Object
Use #configure instead.
4 5 6 7 |
# File 'lib/vcr/deprecations.rb', line 4 def config warn "WARNING: `VCR.config` is deprecated. Use VCR.configure instead." configure { |c| yield c } end |
#configuration ⇒ VCR::Configuration
Returns the VCR configuration.
209 210 211 |
# File 'lib/vcr.rb', line 209 def configuration @configuration end |
#configure {|config| ... } ⇒ void
This method returns an undefined value.
Used to configure VCR.
204 205 206 |
# File 'lib/vcr.rb', line 204 def configure yield configuration end |
#cucumber_tags {|t| ... } ⇒ void
This method returns an undefined value.
Sets up ‘Before` and `After` cucumber hooks in order to use VCR with particular cucumber tags.
226 227 228 229 |
# File 'lib/vcr.rb', line 226 def (&block) main_object = eval('self', block.binding) yield VCR::CucumberTags.new(main_object) end |
#current_cassette ⇒ nil, VCR::Cassette
The currently active cassette.
48 49 50 |
# File 'lib/vcr.rb', line 48 def current_cassette cassettes.last end |
#eject_cassette(options = {}) ⇒ VCR::Cassette?
Ejects the current cassette. The cassette will no longer be used. In addition, any newly recorded HTTP interactions will be written to disk.
153 154 155 156 157 158 159 |
# File 'lib/vcr.rb', line 153 def eject_cassette( = {}) cassette = cassettes.last cassette.eject() if cassette cassette ensure cassettes.pop end |
#fibers_available? ⇒ Boolean
349 350 351 |
# File 'lib/vcr.rb', line 349 def fibers_available? @fibers_available end |
#http_interactions ⇒ Object
294 295 296 297 |
# File 'lib/vcr.rb', line 294 def http_interactions return current_cassette.http_interactions if current_cassette VCR::Cassette::HTTPInteractionList::NullList end |
#insert_cassette(name, options = {}) ⇒ VCR::Cassette
If you use this method you must call ‘eject_cassette` when you are done. It is generally recommended that you use #use_cassette unless your code-under-test cannot be run as a block.
Inserts the named cassette using the given cassette options. New HTTP interactions, if allowed by the cassette’s ‘:record` option, will be recorded to the cassette. The cassette’s existing HTTP interactions will be used to stub requests, unless prevented by the cassete’s ‘:record` option.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/vcr.rb', line 126 def insert_cassette(name, = {}) if turned_on? if cassettes.any? { |c| c.name == name } raise ArgumentError.new("There is already a cassette with the same name (#{name}). You cannot nest multiple cassettes with the same name.") end cassette = Cassette.new(name, ) cassettes.push(cassette) cassette elsif !ignore_cassettes? = "VCR is turned off. You must turn it on before you can insert a cassette. " + "Or you can use the `:ignore_cassettes => true` option to completely ignore cassette insertions." raise TurnedOffError.new() end end |
#library_hooks ⇒ Object
316 317 318 |
# File 'lib/vcr.rb', line 316 def library_hooks @library_hooks end |
#link_context(from_thread, to_key) ⇒ Object
339 340 341 |
# File 'lib/vcr.rb', line 339 def link_context(from_thread, to_key) @context[to_key] = get_context(from_thread) end |
#real_http_connections_allowed? ⇒ Boolean
300 301 302 303 |
# File 'lib/vcr.rb', line 300 def real_http_connections_allowed? return current_cassette.recording? if current_cassette !!(configuration.allow_http_connections_when_no_cassette? || !turned_on?) end |
#record_http_interaction(interaction) ⇒ Object
331 332 333 334 335 336 |
# File 'lib/vcr.rb', line 331 def record_http_interaction(interaction) return unless cassette = current_cassette return if VCR.request_ignorer.ignore?(interaction.request) cassette.record_http_interaction(interaction) end |
#request_ignorer ⇒ Object
311 312 313 |
# File 'lib/vcr.rb', line 311 def request_ignorer @request_ignorer end |
#request_matchers ⇒ RequestMatcherRegistry
Returns the request matcher registry.
306 307 308 |
# File 'lib/vcr.rb', line 306 def request_matchers @request_matchers end |
#turn_off!(options = {}) ⇒ void
This method returns an undefined value.
Turns VCR off, so that it no longer handles every HTTP request.
259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/vcr.rb', line 259 def turn_off!( = {}) if VCR.current_cassette raise CassetteInUseError, "A VCR cassette is currently in use (#{VCR.current_cassette.name}). " + "You must eject it before you can turn VCR off." end set_context_value(:ignore_cassettes, [:ignore_cassettes]) = .keys - [:ignore_cassettes] if .any? raise ArgumentError.new("You passed some invalid options: #{.inspect}") end set_context_value(:turned_off, true) end |
#turn_on! ⇒ void
This method returns an undefined value.
Turns on VCR, if it has previously been turned off.
279 280 281 |
# File 'lib/vcr.rb', line 279 def turn_on! set_context_value(:turned_off, false) end |
#turned_off(options = {}) ⇒ void
This method returns an undefined value.
Turns VCR off for the duration of a block.
239 240 241 242 243 244 245 246 247 |
# File 'lib/vcr.rb', line 239 def turned_off( = {}) turn_off!() begin yield ensure turn_on! end end |
#turned_on? ⇒ Boolean
Normally VCR is always turned on; it will only be off if you have explicitly turned it off.
Returns whether or not VCR is turned on.
289 290 291 |
# File 'lib/vcr.rb', line 289 def turned_on? !context_value(:turned_off) end |
#unlink_context(key) ⇒ Object
344 345 346 |
# File 'lib/vcr.rb', line 344 def unlink_context(key) @context.delete(key) end |
#use_cassette(name, options = {}) {|cassette| ... } ⇒ void
This method returns an undefined value.
Inserts a cassette using the given name and options, runs the given block, and ejects the cassette.
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/vcr.rb', line 178 def use_cassette(name, = {}, &block) unless block raise ArgumentError, "`VCR.use_cassette` requires a block. " + "If you cannot wrap your code in a block, use " + "`VCR.insert_cassette` / `VCR.eject_cassette` instead." end cassette = insert_cassette(name, ) begin call_block(block, cassette) ensure eject_cassette end end |
#version ⇒ String
This string also has singleton methods:
-
‘major` [Integer] The major version.
-
‘minor` [Integer] The minor version.
-
‘patch` [Integer] The patch version.
-
‘parts` [Array<Integer>] List of the version parts.
Returns the current VCR version.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/vcr/version.rb', line 11 def version @version ||= begin string = '3.0.0' def string.parts split('.').map { |p| p.to_i } end def string.major parts[0] end def string.minor parts[1] end def string.patch parts[2] end string end end |