Class: SPV::Fixtures::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/site_prism_vcr/fixtures/manager.rb

Overview

Takes cares about inserting and ejecting fixtures from Vcr.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fixtures, options) ⇒ void

Initializes a new instance

Parameters:



26
27
28
# File 'lib/site_prism_vcr/fixtures/manager.rb', line 26

def initialize(fixtures, options)
  @fixtures, @options = fixtures, options
end

Class Method Details

.inject(fixtures, options) ⇒ SPV::Fixtures::Manager

Initializes a new instance of the fixtures manager class, injects given fixtures into VCR, returns an instance of the fixtures manager class

Parameters:

Returns:



14
15
16
17
18
# File 'lib/site_prism_vcr/fixtures/manager.rb', line 14

def self.inject(fixtures, options)
  manager = new(fixtures, options)
  manager.inject
  manager
end

Instance Method Details

#ejectvoid

This method returns an undefined value.

Ejects only fixtures from Vcr which are injected by this instance of the fixtures manager class.



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/site_prism_vcr/fixtures/manager.rb', line 49

def eject
  inserted_names = @fixtures.map(&:name)

  # TODO: find better way, may be some pull request to the VCR?
  VCR.send(:cassettes).delete_if do |cassette|
    if remove = inserted_names.include?(cassette.name)
      cassette.eject
    end

    remove
  end
end

#injectvoid

This method returns an undefined value.

Injects given fixtures to Vcr.

Raises:

  • (ArgumentError)

    If a list of fixtures is empty.



35
36
37
38
39
40
41
42
43
# File 'lib/site_prism_vcr/fixtures/manager.rb', line 35

def inject
  raise ArgumentError.new(
    'No fixtures were specified to insert them into VCR'
  ) if @fixtures.size == 0

  @fixtures.each do |fixture|
    VCR.insert_cassette fixture.name, fixture.options
  end
end