Class: VCR::Cassette

Inherits:
Object
  • Object
show all
Defined in:
lib/vcr/cassette.rb,
lib/vcr/deprecations.rb

Constant Summary collapse

VALID_RECORD_MODES =
[:all, :none, :new_episodes].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Cassette

Returns a new instance of Cassette.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/vcr/cassette.rb', line 10

def initialize(name, options = {})
  @name = name
  @record_mode = options[:record] || VCR::Config.default_cassette_options[:record]
  @allow_real_http_lambda = allow_real_http_lambda_for(options[:allow_real_http] || VCR::Config.default_cassette_options[:allow_real_http])

  deprecate_unregistered_record_mode
  raise_error_unless_valid_record_mode(record_mode)

  set_http_connections_allowed
  load_recorded_interactions
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/vcr/cassette.rb', line 8

def name
  @name
end

#record_modeObject (readonly)

Returns the value of attribute record_mode.



8
9
10
# File 'lib/vcr/cassette.rb', line 8

def record_mode
  @record_mode
end

Instance Method Details

#allow_real_http_requests_to?(uri) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/vcr/cassette.rb', line 40

def allow_real_http_requests_to?(uri)
  @allow_real_http_lambda ? @allow_real_http_lambda.call(uri) : false
end

#cache_file(*args) ⇒ Object



23
24
25
26
# File 'lib/vcr/deprecations.rb', line 23

def cache_file(*args)
  warn "WARNING: VCR::Cassette#cache_file is deprecated.  Instead, use: VCR::Cassette#file."
  file(*args)
end

#destroy!(*args) ⇒ Object



18
19
20
21
# File 'lib/vcr/deprecations.rb', line 18

def destroy!(*args)
  warn "WARNING: VCR::Cassette#destroy! is deprecated.  Instead, use: VCR::Cassette#eject."
  eject(*args)
end

#ejectObject



22
23
24
25
26
# File 'lib/vcr/cassette.rb', line 22

def eject
  write_recorded_interactions_to_disk
  VCR.http_stubbing_adapter.restore_stubs_checkpoint(name)
  restore_http_connections_allowed
end

#fileObject



36
37
38
# File 'lib/vcr/cassette.rb', line 36

def file
  File.join(VCR::Config.cassette_library_dir, "#{name.to_s.gsub(/[^\w\-\/]+/, '_')}.yml") if VCR::Config.cassette_library_dir
end

#record_http_interaction(interaction) ⇒ Object



32
33
34
# File 'lib/vcr/cassette.rb', line 32

def record_http_interaction(interaction)
  recorded_interactions << interaction
end

#recorded_interactionsObject



28
29
30
# File 'lib/vcr/cassette.rb', line 28

def recorded_interactions
  @recorded_interactions ||= []
end