module Capybara::Screenshot::RSpec::HtmlEmbedReporter

Public Instance Methods

extra_failure_content_with_screenshot(exception) click to toggle source
# File lib/capybara-screenshot/rspec/html_embed_reporter.rb, line 11
def extra_failure_content_with_screenshot(exception)
  result  = extra_failure_content_without_screenshot(exception)
  example = @failed_examples.last
  # Ignores saved html file, only saved image will be embedded (if present)
  if (screenshot = example.metadata[:screenshot]) && screenshot[:image]
    image = File.binread(screenshot[:image])
    encoded_img = Base64.encode64(image)
    result += "<img src='data:image/png;base64,#{encoded_img}' style='display: block'>"
  end
  result
end