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
- FOOTER_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
The Set of deprecation notifications
Attributes made readable for ERb
The counter for failed example IDs
The Array of failed examples
Public Instance Methods
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
Callback – Add a deprecation warning.
# File lib/rspec/core/formatters/webkit.rb, line 237 def deprecation( notification ) @deprecations.add( notification ) end
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
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
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
Callback called by each example group when it's entered –
# 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
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
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
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
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
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
Link the filename and line number in the given line
from a backtrace.
# File lib/rspec/core/formatters/webkit.rb, line 281 def link_backtrace_line( line ) return line.strip.sub( /(?<filename>[^:]*\.rb):(?<line>\d*)(?<rest>.*)/ ) do match = $~ fullpath = File.expand_path( match[:filename] ) %|<a href="txmt://open?url=file://%s&line=%s">%s:%s</a>%s| % [ fullpath, match[:line], match[:filename], match[:line], h(match[:rest]) ] end end
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
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 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 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 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 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
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 the page by rendering the header.
# File lib/rspec/core/formatters/webkit.rb, line 133 def start( notification ) super @output.puts self.render_header( notification ) @output.flush end
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
Create a new formatter
# 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