Pattern to match for excluding lines from backtraces
The base HREF used in the header to map stuff to the datadir
Look up the datadir falling back to a relative path (mostly for prerelease testing)
The page part templates
Figure out which class pending-example-fixed errors are (2.8 change)
The directory to grab ERb templates out of
Version constant
Attributes made readable for ERb
Attributes made readable for ERb
Attributes made readable for ERb
The counter for failed example IDs
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)}&line=#{$2}\">#{$1}:#{$2}</a> "
end
end
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
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
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
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
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
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
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
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
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
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
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
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
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
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