class SplithtmlFormatter

Public Class Methods

new(output) click to toggle source
Calls superclass method
# File lib/splithtml_formatter.rb, line 28
def initialize(output)
    super(output)
    @failed_examples = []
    @example_group_number = 0
    @example_number = 0
    @failure_number = 0
    @pending_number = 0
    @header_red = nil
    @run_time = 0.0
    @test_file_name = ""
    @start_time = 0.0
    @end_time = 0.0
end

Public Instance Methods

example_failed(failure) click to toggle source
# File lib/splithtml_formatter.rb, line 119
def example_failed(failure)
    @failed_examples << failure.example
    unless @header_red
        @header_red = true
        @printer.make_header_red
    end

    unless @example_group_red
        @example_group_red = true
        @printer.make_example_group_header_red(0)
    end

    @printer.move_progress(100)

    example = failure.example
    exception = failure.exception
    exception_details = if exception
    {
      :message => exception.message,
      :backtrace => failure.formatted_backtrace.join("\n")
    }
    else
        false
    end
    extra = extra_failure_content(exception)
    debug_print("extra: #{extra}")
   @printer.print_example_failed(
      example.execution_result.pending_fixed,
      example.description,
      example.execution_result.run_time,
      @failed_examples.size,
      exception_details,
      (extra == "") ? false : extra,
      true
      )
    @printer.flush()
    @failure_number += 1
    @run_time += example.execution_result.run_time
end
example_group_finished(notification) click to toggle source
Calls superclass method
# File lib/splithtml_formatter.rb, line 97
def example_group_finished(notification)
    super
    @printer.print_example_group_end()
    test_file_path = File.expand_path(notification.group.file_path)
    @end_time = Time.now().to_f()
    @printer.print_summary(false, @run_time, @example_number, @failure_number, @pending_number, test_file_path, @start_time, @end_time)
    @printer.flush()
    debug_print("finished:" + @printer.object_id.to_s)
end
example_group_started(notification) click to toggle source
Calls superclass method
# File lib/splithtml_formatter.rb, line 79
def example_group_started(notification)
    super
    @start_time = Time.now().to_f()
    @example_number = 0
    @failure_number = 0
    @pending_number = 0
    @header_red = false
    @run_time = 0.0
    @example_group_red = false
    @example_group_number += 1
    test_file_name = File.basename(notification.group.file_path)
    @printer = new_html(notification.group.description.to_s)
    @printer.print_html_start(test_file_name)
    @printer.print_example_group_start(notification.group.description)
    @printer.flush()
    debug_print("start:" + @printer.object_id.to_s)
end
example_passed(passed) click to toggle source
# File lib/splithtml_formatter.rb, line 112
def example_passed(passed)
    @printer.move_progress(100)
    @printer.print_example_passed( passed.example.description, passed.example.execution_result.run_time )
    @printer.flush()
    @run_time += passed.example.execution_result.run_time
end
example_pending(pending) click to toggle source
# File lib/splithtml_formatter.rb, line 159
def example_pending(pending)
   example = pending.example
    @printer.make_header_yellow unless @header_red
    @printer.make_example_group_header_yellow(example_group_number) unless @example_group_red
    @printer.move_progress(100)
    @printer.print_example_pending( example.description, example.execution_result.pending_message)
    @printer.flush()
    @pending_number += 1
    @run_time += example.execution_result.run_time
end
example_started(notification) click to toggle source
# File lib/splithtml_formatter.rb, line 107
def example_started(notification)
    @example_number += 1
    @printer.print_example_start()
end
example_step_failed(example, type, message, options) click to toggle source
# File lib/splithtml_formatter.rb, line 181
def example_step_failed(example, type, message, options)
    
    unless @header_red
        @header_red = true
        @printer.make_header_red
    end

    unless @example_group_red
        @example_group_red = true
        @printer.make_example_group_header_red(0)
    end

    @printer.move_progress(100)

    exception = example.exception
    exception_details = if exception
    {
      :message => exception.message,
      :backtrace => format_backtrace(exception.backtrace, example).join("\n")
    }
    else
        false
    end

    @printer.print_example_failed(
        example.execution_result.pending_fixed,
        type.to_s().upcase() + ' ' + message,
        0,
        @failed_examples.size,
        exception_details,
        false,
        true
    )

    @printer.flush()
    @failure_number += 1
end
example_step_passed(example, type, message, options) click to toggle source
# File lib/splithtml_formatter.rb, line 175
def example_step_passed(example, type, message, options)
    @printer.move_progress(100)
    @printer.print_example_passed( type.to_s().upcase() + ' ' + message, 0 )
    @printer.flush()
end
example_step_pending(example, type, message, options) click to toggle source
# File lib/splithtml_formatter.rb, line 219
def example_step_pending(example, type, message, options)
    @printer.make_header_yellow unless @header_red
    @printer.make_example_group_header_yellow(example_group_number) unless @example_group_red
    @printer.move_progress(100)
    @printer.print_example_pending( type.to_s().upcase() + ' ' + message, '')
    @printer.flush()
    @pending_number += 1
end
example_step_started(example, type, message, options) click to toggle source

support for github.com/railsware/rspec-example_steps

# File lib/splithtml_formatter.rb, line 171
def example_step_started(example, type, message, options)
    example_started(example)
end
extra_failure_content(failure) click to toggle source
# File lib/splithtml_formatter.rb, line 228
def extra_failure_content(failure)
  RSpec::Support.require_rspec_core "formatters/snippet_extractor"
  backtrace = failure.exception.backtrace.map {|line| RSpec.configuration.backtrace_formatter.backtrace_line(line)}
  backtrace.compact!
  @snippet_extractor ||= RSpec::Core::Formatters::SnippetExtractor.new
  "    <pre class=\"ruby\"><code>#{@snippet_extractor.snippet(backtrace)}</code></pre>"
end
message(message) click to toggle source
# File lib/splithtml_formatter.rb, line 72
def message(message)
end
start(example_count) click to toggle source
Calls superclass method
# File lib/splithtml_formatter.rb, line 75
def start(example_count)
    super(example_count)
end

Private Instance Methods

method_missing(m, *a, &b) click to toggle source
# File lib/splithtml_formatter.rb, line 44
def method_missing(m, *a, &b)
end
new_html(description) click to toggle source
# File lib/splithtml_formatter.rb, line 47
def new_html(description)
    debug_print("description:" + description)
    basename = "#{description.gsub(/[^a-zA-Z0-9]+/, '-')}"
    max_filename_size = (ENV['MAX_FILENAME_SIZE'] || 2**8).to_i
    basename = basename[0..max_filename_size] if basename.length > max_filename_size
    debug_print("basename:" + basename)
    basedir = ENV['HTML_REPORTS'] || File.expand_path("#{Dir.getwd}/#{PREFIX.downcase}/reports")
    debug_print("basedir:" + basedir)
    FileUtils.mkdir_p(basedir)
    full_path = "#{basedir}/#{PREFIX.upcase}-#{basename}" 
    debug_print("full_path:" + full_path)  
    suffix = "html"
    filename = [full_path, suffix].join(".")
    i = 0
    while File.exists?(filename) && i < 2**15
        filename = [full_path, i, suffix].join(".")
        i += 1
    end
    debug_print("filename:" + filename)
    file_out_put = FileOutput.new(filename)
    return SplitHtmlPrinter.new(file_out_put)
end