RSpec::Core::Formatters::

WebKit

class
Superclass
RSpec::Core::Formatters::BaseTextFormatter
Included Modules
ERB::Util

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)

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)

TEMPLATE_DIR

The directory to grab ERb templates out of

VERSION

Version constant

Attributes

example_count[R]

Attributes made readable for ERb

example_group_number[R]

Attributes made readable for ERb

example_number[R]

Attributes made readable for ERb

failcounter[RW]

The counter for failed example IDs

Public Instance Methods

anchor
add_example_group( example_group )
anchor
backtrace_line( line )

Format backtrace lines to include a textmate link to the file/line in question.

# File lib/rspec/core/formatters/webkit.rb, line 181
def backtrace_line( line )
        return nil unless line = super
        return nil if line =~ BACKTRACE_EXCLUDE_PATTERN
        return h( line.strip ).gsub( %r([^:]*\.rb):(\d*)/ ) do
                "<a href=\"txmt://open?url=file://#{File.expand_path($1)}&amp;line=#{$2}\">#{$1}:#{$2}</a> "
        end
end
anchor
dump_failures( *unused )

Returns content to be output when a failure occurs during the run; overridden to do nothing, as failures are handled by example_failed.

# File lib/rspec/core/formatters/webkit.rb, line 204
def dump_failures( *unused )
end
anchor
dump_summary( duration, example_count, failure_count, pending_count )

Output the content generated at the end of the run.

# File lib/rspec/core/formatters/webkit.rb, line 209
def dump_summary( duration, example_count, failure_count, pending_count )
        @output.puts self.render_footer( duration, example_count, failure_count, pending_count )
        @output.flush
end
anchor
example_failed( example )

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

# File lib/rspec/core/formatters/webkit.rb, line 156
def example_failed( example )
        super

        counter   = self.failcounter += 1
        exception = example.metadata[:execution_result][: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
anchor
example_group_started( example_group )

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

# File lib/rspec/core/formatters/webkit.rb, line 89
def example_group_started( example_group )
        super
        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 %Q{<section class="example-group">}
        else
                @output.puts %Q{<dd class="nested-group"><section class="example-group">}
        end

        @output.puts %Q{  <dl>},
                %Q{  <dt id="%s">%s</dt>} % [
                     example_group.name.gsub(%r[\W_]+/, '-').downcase,
                        h(example_group.description)
                ]
        @output.flush
end
Also aliased as: add_example_group
anchor
example_passed( example )

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

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

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

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

Callback – called when an example is entered

# File lib/rspec/core/formatters/webkit.rb, line 140
def example_started( example )
        @example_number += 1
        Thread.current[ 'logger-output' ] ||= []
        Thread.current[ 'logger-output' ].clear
end
anchor
extra_failure_content( exception )

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 193
def extra_failure_content( exception )
        return '' unless exception
        backtrace = exception.backtrace.find {|line| line !~ BACKTRACE_EXCLUDE_PATTERN }
        # $stderr.puts "Using backtrace line %p to extract snippet" % [ backtrace ]
        snippet = @snippet_extractor.snippet([ backtrace ])
        return "    <pre class=\"ruby\"><code>#{snippet}</code></pre>"
end
anchor
load_template( templatepath )

Load the ERB template at templatepath and return it.

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

Fetch any log messages added to the thread-local Array

# File lib/rspec/core/formatters/webkit.rb, line 122
def log_messages
        return Thread.current[ 'logger-output' ] || []
end
anchor anchor
render_header( example_count )

Render the header template in the context of the receiver.

# File lib/rspec/core/formatters/webkit.rb, line 216
def render_header( example_count )
        template = self.load_template( HEADER_TEMPLATE )
        return template.result( binding() )
end
anchor
start( example_count )

Start the page by rendering the header.

# File lib/rspec/core/formatters/webkit.rb, line 82
def start( example_count )
        @output.puts self.render_header( example_count )
        @output.flush
end
anchor
start_dump()

Callback – called when the examples are finished.

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

        @output.flush
end

Protected Instance Methods

anchor
initialize( output )

Create a new formatter

# File lib/rspec/core/formatters/webkit.rb, line 53
def initialize( output ) # :notnew:
        super
        @previous_nesting_depth = 0
        @example_number = 0
        @failcounter = 0
        @snippet_extractor = RSpec::Core::Formatters::SnippetExtractor.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),
        }

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