class RSpec::Core::Formatters::WebKit

Constants

BACKTRACE_EXCLUDE_PATTERN

Pattern to match for excluding lines from backtraces

BASE_HREF

The base HREF used in the header to map stuff to the datadir

DATADIR

Look up the datadir falling back to a relative path (mostly for prerelease testing)

DEPRECATIONS_TEMPLATE
FAILED_EXAMPLE_TEMPLATE
HEADER_TEMPLATE

The page part templates

PASSED_EXAMPLE_TEMPLATE
PENDFIX_EXAMPLE_TEMPLATE
PENDING_EXAMPLE_TEMPLATE
PENDING_FIXED_EXCEPTION

Figure out which class pending-example-fixed errors are (2.8 change)

SEED_TEMPLATE
SUMMARY_TEMPLATE
TEMPLATE_DIR

The directory to grab ERb templates out of

VERSION

Version constant

Attributes

deprecations[R]

The Set of deprecation notifications

example_count[R]

Attributes made readable for ERb

failcounter[RW]

The counter for failed example IDs

failed_examples[R]

The Array of failed examples

Public Instance Methods

close( notification ) click to toggle source

Callback – called at the very end.

# File lib/rspec/core/formatters/webkit.rb, line 260
def close( notification )
        footer = self.render_footer( notification )
        @output.puts( footer )
        @output.flush
end
deprecation( notification ) click to toggle source

Callback – Add a deprecation warning.

# File lib/rspec/core/formatters/webkit.rb, line 237
def deprecation( notification )
        @deprecations.add( notification )
end
deprecation_summary( notification ) click to toggle source

Callback – Called at the end with a summary of any deprecations encountered during the run.

# File lib/rspec/core/formatters/webkit.rb, line 244
def deprecation_summary( notification )
        html = self.render_deprecations
        @output.puts( html )
        @output.flush
end
dump_summary( summary ) click to toggle source

Output the content generated at the end of the run.

# File lib/rspec/core/formatters/webkit.rb, line 229
def dump_summary( summary )
        html = self.render_summary( summary )
        @output.puts( html )
        @output.flush
end
example_failed( notification ) click to toggle source

Callback – called when an example is exited with a failure.

# File lib/rspec/core/formatters/webkit.rb, line 201
def example_failed( notification )
        example   = notification.example

        self.failed_examples << example
        counter   = self.failed_examples.size

        exception = notification.exception
        extra     = self.extra_failure_content( exception )
        template  = if exception.is_a?( PENDING_FIXED_EXCEPTION )
                then @example_templates[:pending_fixed]
                else @example_templates[:failed]
                end

        @output.puts( template.result(binding()) )
        @output.flush
end
example_group_started( notification ) click to toggle source

Callback called by each example group when it's entered –

Calls superclass method
# File lib/rspec/core/formatters/webkit.rb, line 141
def example_group_started( notification )
        super
        example_group = notification.group
        nesting_depth = example_group.ancestors.length

        # Close the previous example groups if this one isn't a
        # descendent of the previous one
        if @previous_nesting_depth.nonzero? && @previous_nesting_depth >= nesting_depth
                ( @previous_nesting_depth - nesting_depth + 1 ).times do
                        @output.puts "  </dl>", "</section>", "  </dd>"
                end
        end

        @output.puts "<!-- nesting: %d, previous: %d -->" %
                [ nesting_depth, @previous_nesting_depth ]
        @previous_nesting_depth = nesting_depth

        if @previous_nesting_depth == 1
                @output.puts %{<section class="example-group">}
        else
                @output.puts %{<dd class="nested-group"><section class="example-group">}
        end

        @output.puts %{  <dl>},
                %{  <dt id="%s">%s</dt>} % [
                        example_group.name.gsub(/[\W_]+/, '-').downcase,
                        h(example_group.description)
                ]
        @output.flush
end
example_passed( notification ) click to toggle source

Callback – called when an example is exited with no failures.

# File lib/rspec/core/formatters/webkit.rb, line 192
def example_passed( notification )
        example = notification.example
        status = 'passed'
        @output.puts( @example_templates[:passed].result(binding()) )
        @output.flush
end
example_pending( notification ) click to toggle source

Callback – called when an example is exited via a 'pending'.

# File lib/rspec/core/formatters/webkit.rb, line 220
def example_pending( notification )
        example = notification.example
        status = 'pending'
        @output.puts( @example_templates[:pending].result(binding()) )
        @output.flush
end
example_started( notification ) click to toggle source

Callback – called when an example is entered

# File lib/rspec/core/formatters/webkit.rb, line 186
def example_started( notification )
        self.log_messages.clear
end
extra_failure_content( exception ) click to toggle source

Return any stuff that should be appended to the current example because it's failed. Returns a snippet of the source around the failure.

# File lib/rspec/core/formatters/webkit.rb, line 294
def extra_failure_content( exception )
        return '' unless exception

        backtrace = ( exception.backtrace || [] ).map do |line|
                RSpec.configuration.backtrace_formatter.backtrace_line( line )
        end.compact

        snippet = @snippet_extractor.snippet( backtrace )
        return "    <pre class=\"ruby\"><code>#{snippet}</code></pre>"
end
find_shared_group( example ) click to toggle source

Find the innermost shared example group for the given example.

# File lib/rspec/core/formatters/webkit.rb, line 307
def find_shared_group( example )
        groups = example.example_group.parent_groups + [example.example_group]
        return groups.find {|group| group.metadata[:shared_group_name]}
end
format_backtrace( notification ) click to toggle source

Overriden to add txmt: links to the file paths in the backtrace.

# File lib/rspec/core/formatters/webkit.rb, line 272
def format_backtrace( notification )
        lines = notification.formatted_backtrace
        return lines.map do |line|
                link_backtrace_line( line )
        end
end
load_template( templatepath ) click to toggle source

Load the ERB template at templatepath and return it.

# File lib/rspec/core/formatters/webkit.rb, line 353
def load_template( templatepath )
        return ERB.new( templatepath.read, nil, '%<>' ).freeze
end
log_messages() click to toggle source

Fetch any log messages added to the thread-local Array

# File lib/rspec/core/formatters/webkit.rb, line 123
def log_messages
        return Thread.current[ 'logger-output' ] ||= []
end
render_deprecations() click to toggle source

Render the deprecation summary template in the context of the receiver.

# File lib/rspec/core/formatters/webkit.rb, line 332
def render_deprecations
        template = self.load_template( DEPRECATIONS_TEMPLATE )
        return template.result( binding() )
end
render_header( notification ) click to toggle source

Render the header template in the context of the receiver.

# File lib/rspec/core/formatters/webkit.rb, line 318
def render_header( notification )
        template = self.load_template( HEADER_TEMPLATE )
        return template.result( binding() )
end
render_seed( notification ) click to toggle source

Render the seed template in the context of the receiver.

# File lib/rspec/core/formatters/webkit.rb, line 339
def render_seed( notification )
        template = self.load_template( SEED_TEMPLATE )
        return template.result( binding() )
end
render_summary( summary ) click to toggle source

Render the summary template in the context of the receiver.

# File lib/rspec/core/formatters/webkit.rb, line 325
def render_summary( summary )
        template = self.load_template( SUMMARY_TEMPLATE )
        return template.result( binding() )
end
seed( notification ) click to toggle source

Callback – called with the random seed if the test suite is run with random ordering.

# File lib/rspec/core/formatters/webkit.rb, line 252
def seed( notification )
        return unless notification.seed_used?
        html = self.render_seed( notification )
        @output.puts( html )
end
start( notification ) click to toggle source

Start the page by rendering the header.

Calls superclass method
# File lib/rspec/core/formatters/webkit.rb, line 133
def start( notification )
        super
        @output.puts self.render_header( notification )
        @output.flush
end
start_dump( notification ) click to toggle source

Callback – called when the examples are finished.

# File lib/rspec/core/formatters/webkit.rb, line 174
def start_dump( notification )
        @previous_nesting_depth.downto( 1 ) do |i|
                @output.puts "  </dl>",
                             "</section>"
                @output.puts "  </dd>" unless i == 1
        end

        @output.flush
end

Protected Instance Methods

initialize( output ) click to toggle source

Create a new formatter

Calls superclass method
# File lib/rspec/core/formatters/webkit.rb, line 83
def initialize( output ) # :notnew:
        super
        @previous_nesting_depth = 0
        @failcounter = 0
        @snippet_extractor = RSpec::Core::Formatters::HtmlSnippetExtractor.new
        @example_templates = {
                :passed        => self.load_template(PASSED_EXAMPLE_TEMPLATE),
                :failed        => self.load_template(FAILED_EXAMPLE_TEMPLATE),
                :pending       => self.load_template(PENDING_EXAMPLE_TEMPLATE),
                :pending_fixed => self.load_template(PENDFIX_EXAMPLE_TEMPLATE),
        }

        @deprecation_stream = []
        @summary_stream     = []
        @failed_examples    = []

        @deprecations = Set.new

        Thread.current['logger-output'] = []
end