module Sweet module Format module RSpec class Example class << self def from_output(data) data = JSON.parse(data, symbolize_names: true) if data.is_a? String case data[:status] when 'pending' message = data[:pending_message] when 'failed' e = data[:exception] message = "#{e[:class]}\n#{e[:message]}" end backtrace = data[:exception][:backtrace] if data[:exception] new name: data[:full_description], status: data[:status], file_path: data[:file_path], line_number: data[:line_number], duration: data[:run_time], message: message, backtrace: backtrace, screenshot: data[:screenshot] end end attr_accessor :name, :status, :file_path, :line_number, :message, :backtrace, :screenshot def initialize(opts = {}) @name = opts[:name] @status = opts[:status].to_sym if opts[:status] @file_path = sanitize_file_path(opts[:file_path]) @line_number = opts[:line_number] @duration = opts[:duration] @message = opts[:message] @screenshot = opts[:screenshot] end def duration @duration * 1_000_000_000 end private def sanitize_file_path(file_path) file_path.gsub('./', '') end end end end end