Class: Betamax::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/betamax/player.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(example, tapes_folder:) ⇒ Player

Returns a new instance of Player.



5
6
7
8
9
10
# File 'lib/betamax/player.rb', line 5

def initialize example, tapes_folder:
  @example = example
  @tapes_folder = tapes_folder
  @tape = Tape.from_rspec_example(example, tapes_folder:)
  @root_proxy = nil
end

Instance Attribute Details

#root_proxyObject (readonly)

Returns the value of attribute root_proxy.



3
4
5
# File 'lib/betamax/player.rb', line 3

def root_proxy
  @root_proxy
end

#tapeObject (readonly)

Returns the value of attribute tape.



3
4
5
# File 'lib/betamax/player.rb', line 3

def tape
  @tape
end

#tapes_folderObject (readonly)

Returns the value of attribute tapes_folder.



3
4
5
# File 'lib/betamax/player.rb', line 3

def tapes_folder
  @tapes_folder
end

Instance Method Details

#playObject



12
13
14
15
16
# File 'lib/betamax/player.rb', line 12

def play
  insert_tape
  @example.run
  eject_tape unless @example.exception
end

#record(object) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/betamax/player.rb', line 18

def record object
  recorder = if @tape.exists?
               MethodPlayer.new recording: @tape.recording
             else
               MethodRecorder.new object:, recording: @tape.recording
             end

  @root_proxy = RecordedObject.new object:, recorder:
end