Skip to content

Instantly share code, notes, and snippets.

@Fitzsimmons
Created February 18, 2014 22:14
Show Gist options
  • Save Fitzsimmons/9081491 to your computer and use it in GitHub Desktop.
Save Fitzsimmons/9081491 to your computer and use it in GitHub Desktop.
require "rspec/core/formatters/base_text_formatter"
require 'headless'
require 'fileutils'
class AcceptanceVideoFormatter < RSpec::Core::Formatters::BaseTextFormatter
def initialize(output)
@headless = Headless.new(
video: {
nomouse: true,
log_file_path: "/tmp/headless.txt",
codec: "libx264 -preset ultrafast -pix_fmt yuv420p",
tmp_file_path: "/tmp/.headless_ffmpeg_tmp.mp4"
}
)
@headless.start
@counter = 0
@timestamp = Time.now.strftime("%Y%m%d%H%M%S")
super(output)
end
def example_started(example)
@counter = @counter + 1
@headless.video.start_capture
output.write "#{example.full_description}:"
output.flush
super(example)
end
def example_passed(example)
@headless.video.stop_and_discard
output.puts " Pass"
end
def example_failed(example)
output.puts " Fail"
dump_failure_info(example)
dump_backtrace(example)
video_file_name = "#{@timestamp}_#{@counter}_#{example.description.parameterize}.mp4"
video_file_path = "/tmp/test_videos/#{video_file_name}"
FileUtils.mkdir_p("/tmp/test_videos")
@headless.video.stop_and_save(video_file_path)
video_file_url = "http://#{local_ip_addr}:7777/#{video_file_name}"
output.puts "Failed run video: " + video_file_url
end
private
def local_ip_addr
orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true # turn off reverse DNS resolution temporarily
UDPSocket.open do |s|
s.connect '64.59.144.16', 1
s.addr.last
end
ensure
Socket.do_not_reverse_lookup = orig
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment