Module: Videotest::Recorder::Rails::SetupAndTeardown

Defined in:
lib/videotest/recorder/rails/setup_and_teardown.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#headlessObject (readonly)

Returns the value of attribute headless.



8
9
10
# File 'lib/videotest/recorder/rails/setup_and_teardown.rb', line 8

def headless
  @headless
end

#video_dirObject (readonly)

Returns the value of attribute video_dir.



8
9
10
# File 'lib/videotest/recorder/rails/setup_and_teardown.rb', line 8

def video_dir
  @video_dir
end

Instance Method Details

#before_setupObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/videotest/recorder/rails/setup_and_teardown.rb', line 10

def before_setup
  @video_dir = ::Rails.root.join("tmp", "videos")
  FileUtils.mkdir_p(video_dir)

  # TODO: Allow configuring parameters.
  @headless = Headless.new(video: { provider: :ffmpeg, codec: :libx264, extra: %w(-preset ultrafast) })
  headless.start
  headless.video.start_capture

  super
end

#before_teardownObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/videotest/recorder/rails/setup_and_teardown.rb', line 22

def before_teardown
  if failures.empty?
    headless.video.stop_and_discard
  else
    video = video_dir.join("failures_#{self.name}.mp4")
    headless.video.stop_and_save(video)
    puts "[Video]: #{video}"
  end
ensure
  super
end