Class: RSpec::Core::Formatters::HtmlFormatter

### Home Classes Methods

### In Files

- lib/rspec/core/formatters/html_formatter.rb

### Parent

RSpec::Core::Formatters::BaseTextFormatter

### Methods

- ::new
- #dump_failures
- #dump_pending
- #dump_summary
- #example_failed
- #example_group_number
- #example_group_started
- #example_number
- #example_passed
- #example_pending
- #example_started
- #extra_failure_content
- #message
- #percent_done
- #start
- #start_dump

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Core
- RSpec::Core::BacktraceCleaner
- RSpec::Core::BacktraceFormatter
- RSpec::Core::CommandLine
- RSpec::Core::Configuration
- RSpec::Core::Configuration::MustBeConfiguredBeforeExampleGroupsError
- RSpec::Core::ConfigurationOptions
- RSpec::Core::ConstMissing
- RSpec::Core::DRbCommandLine
- RSpec::Core::DSL
- RSpec::Core::Deprecation
- RSpec::Core::DrbOptions
- RSpec::Core::Example
- RSpec::Core::Example::NotPendingExampleFixed
- RSpec::Core::Example::Procsy
- RSpec::Core::ExampleGroup
- RSpec::Core::Extensions
- RSpec::Core::Extensions::InstanceEvalWithArgs
- RSpec::Core::Extensions::ModuleEvalWithArgs
- RSpec::Core::Extensions::Ordered
- RSpec::Core::Extensions::Ordered::ExampleGroups
- RSpec::Core::Extensions::Ordered::Examples
- RSpec::Core::FilterManager
- RSpec::Core::FilterManager::BackwardCompatibility
- RSpec::Core::FilterManager::Describable
- RSpec::Core::Formatters
- RSpec::Core::Formatters::BaseFormatter
- RSpec::Core::Formatters::BaseTextFormatter
- RSpec::Core::Formatters::DeprecationFormatter
- RSpec::Core::Formatters::DocumentationFormatter
- RSpec::Core::Formatters::Helpers
- RSpec::Core::Formatters::HtmlFormatter
- RSpec::Core::Formatters::HtmlPrinter
- RSpec::Core::Formatters::JsonFormatter
- RSpec::Core::Formatters::ProgressFormatter
- RSpec::Core::Formatters::SnippetExtractor
- RSpec::Core::Formatters::SnippetExtractor::NullConverter
- RSpec::Core::Formatters::TextMateFormatter
- RSpec::Core::Hooks
- RSpec::Core::Hooks::AfterAllHook
- RSpec::Core::Hooks::AfterHook
- RSpec::Core::Hooks::AroundHook
- RSpec::Core::Hooks::AroundHookCollection
- RSpec::Core::Hooks::BeforeHook
- RSpec::Core::Hooks::GroupHookCollection
- RSpec::Core::Hooks::Hook
- RSpec::Core::Hooks::HookCollection
- RSpec::Core::Hooks::HookCollectionAliases
- RSpec::Core::Hooks::RegistersGlobals
- RSpec::Core::MemoizedHelpers
- RSpec::Core::MemoizedHelpers::BeforeAllMemoizedHash
- RSpec::Core::MemoizedHelpers::ClassMethods
- RSpec::Core::Metadata
- RSpec::Core::Metadata::ExampleMetadataHash
- RSpec::Core::Metadata::GroupMetadataHash
- RSpec::Core::Metadata::MetadataHash
- RSpec::Core::MetadataHashBuilder
- RSpec::Core::MetadataHashBuilder::Common
- RSpec::Core::MetadataHashBuilder::WithConfigWarning
- RSpec::Core::MetadataHashBuilder::WithDeprecationWarning
- RSpec::Core::MockFrameworkAdapter
- RSpec::Core::Parser
- RSpec::Core::Pending
- RSpec::Core::Pending::PendingDeclaredInExample
- RSpec::Core::Pending::PendingExampleFixedError
- RSpec::Core::ProjectInitializer
- RSpec::Core::RakeTask
- RSpec::Core::Reporter
- RSpec::Core::RubyProject
- RSpec::Core::Runner
- RSpec::Core::SharedContext
- RSpec::Core::SharedExampleGroup
- RSpec::Core::SharedExampleGroup::Collection
- RSpec::Core::SharedExampleGroup::Registry
- RSpec::Core::SharedExampleGroup::TopLevelDSL
- RSpec::Core::Time
- RSpec::Core::Version
- RSpec::Core::World
- RSpec::Rake
- RSpec::Runner
- Autotest
- Autotest::Rspec2
- Kernel

No matching classes.

# RSpec::Core::Formatters::HtmlFormatter

### Public Class Methods

new(output) click to toggle source

    # File lib/rspec/core/formatters/html_formatter.rb, line 9
    def initialize(output)
      super(output)
      @example_group_number = 0
      @example_number = 0
      @header_red = nil
      @printer = HtmlPrinter.new(output)
    end

### Public Instance Methods

dump_failures() click to toggle source

    # File lib/rspec/core/formatters/html_formatter.rb, line 136
    def dump_failures
    end

dump_pending() click to toggle source

    # File lib/rspec/core/formatters/html_formatter.rb, line 139
    def dump_pending
    end

dump_summary(duration, example_count, failure_count, pending_count) click to toggle source

    # File lib/rspec/core/formatters/html_formatter.rb, line 142
    def dump_summary(duration, example_count, failure_count, pending_count)
      @printer.print_summary(
        dry_run?,
        duration,
        example_count,
        failure_count,
        pending_count
      )
      @printer.flush
    end

example_failed(example) click to toggle source

    # File lib/rspec/core/formatters/html_formatter.rb, line 70
    def example_failed(example)
      super(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(example_group_number)
      end

      @printer.move_progress(percent_done)

      exception = example.metadata[:execution_result][:exception]
      exception_details = if exception
        {
          :message => exception.message,
          :backtrace => format_backtrace(exception.backtrace, example).join("\n")
        }
      else
        false
      end
      extra = extra_failure_content(exception)

      @printer.print_example_failed(
        exception.pending_fixed?,
        example.description,
        example.execution_result[:run_time],
        @failed_examples.size,
        exception_details,
        (extra == "") ? false : extra,
        true
      )
      @printer.flush
    end

example_group_number() click to toggle source

The number of the currently running example_group

    # File lib/rspec/core/formatters/html_formatter.rb, line 27
    def example_group_number
      @example_group_number
    end

example_group_started(example_group) click to toggle source

    # File lib/rspec/core/formatters/html_formatter.rb, line 42
    def example_group_started(example_group)
      super(example_group)
      @example_group_red = false
      @example_group_number += 1

      unless example_group_number == 1
        @printer.print_example_group_end
      end
      @printer.print_example_group_start( example_group_number, example_group.description, example_group.parent_groups.size )
      @printer.flush
    end

example_number() click to toggle source

The number of the currently running example (a global counter)

    # File lib/rspec/core/formatters/html_formatter.rb, line 32
    def example_number
      @example_number
    end

example_passed(example) click to toggle source

    # File lib/rspec/core/formatters/html_formatter.rb, line 64
    def example_passed(example)
      @printer.move_progress(percent_done)
      @printer.print_example_passed( example.description, example.execution_result[:run_time] )
      @printer.flush
    end

example_pending(example) click to toggle source

    # File lib/rspec/core/formatters/html_formatter.rb, line 108
    def 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(percent_done)
      @printer.print_example_pending( example.description, example.metadata[:execution_result][:pending_message] )
      @printer.flush
    end

example_started(example) click to toggle source

    # File lib/rspec/core/formatters/html_formatter.rb, line 59
    def example_started(example)
      super(example)
      @example_number += 1
    end

extra_failure_content(exception) click to toggle source

Override this method if you wish to output extra HTML for a failed spec. For example, you could output links to images or other files produced during the specs.

    # File lib/rspec/core/formatters/html_formatter.rb, line 120
    def extra_failure_content(exception)
      require 'rspec/core/formatters/snippet_extractor'
      backtrace = exception.backtrace.map {|line| backtrace_line(line)}
      backtrace.compact!
      @snippet_extractor ||= SnippetExtractor.new
      "    <pre class=\"ruby\"><code>#{@snippet_extractor.snippet(backtrace)}</code></pre>"
    end

message(message) click to toggle source

    # File lib/rspec/core/formatters/html_formatter.rb, line 23
    def message(message)
    end

percent_done() click to toggle source

    # File lib/rspec/core/formatters/html_formatter.rb, line 128
    def percent_done
      result = 100.0
      if @example_count > 0
        result = ((example_number).to_f / @example_count.to_f * 1000).to_i / 10.0
      end
      result
    end

start(example_count) click to toggle source

    # File lib/rspec/core/formatters/html_formatter.rb, line 36
    def start(example_count)
      super(example_count)
      @printer.print_html_start
      @printer.flush
    end

start_dump() click to toggle source

    # File lib/rspec/core/formatters/html_formatter.rb, line 54
    def start_dump
      @printer.print_example_group_end
      @printer.flush
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.