Class: RSpec::Core::Formatters::TextMateFormatter

Inherits:
HtmlFormatter show all
Defined in:
lib/rspec/core/formatters/text_mate_formatter.rb

Overview

Formats backtraces so they're clickable by TextMate

Defined Under Namespace

Classes: NonEscapingHtmlPrinter

Constant Summary

Constant Summary

Constants inherited from BaseTextFormatter

BaseTextFormatter::VT100_COLORS, BaseTextFormatter::VT100_COLOR_CODES

Constants included from Helpers

Helpers::DEFAULT_PRECISION, Helpers::SUB_SECOND_PRECISION

Instance Attribute Summary

Attributes inherited from BaseFormatter

#duration, #example_count, #example_group, #examples, #failed_examples, #failure_count, #output, #pending_count, #pending_examples

Instance Method Summary (collapse)

Methods inherited from HtmlFormatter

#dump_failures, #dump_pending, #dump_summary, #example_failed, #example_group_number, #example_group_started, #example_number, #example_passed, #example_pending, #example_started, #message, #percent_done, #start, #start_dump

Methods inherited from BaseTextFormatter

#close, #color_code_for, #colorise_summary, #colorize, #dump_commands_to_rerun_failed_examples, #dump_failures, #dump_pending, #dump_profile, #dump_profile_slowest_example_groups, #dump_profile_slowest_examples, #dump_summary, #message, #seed, #summary_line

Methods inherited from BaseFormatter

#close, #dump_failures, #dump_pending, #dump_summary, #example_failed, #example_group_finished, #example_group_started, #example_passed, #example_pending, #example_started, #format_backtrace, #message, #start, #start_dump, #stop

Methods included from Helpers

#format_duration, #format_seconds, #pluralize, #strip_trailing_zeroes

Methods included from BacktraceFormatter

#format_backtrace

Constructor Details

- (TextMateFormatter) initialize(output)

A new instance of TextMateFormatter

16
17
18
19
# File 'lib/rspec/core/formatters/text_mate_formatter.rb', line 16
def initialize(output)
  super
  @printer = NonEscapingHtmlPrinter.new(output)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RSpec::Core::Formatters::HtmlFormatter

Instance Method Details

- (Object) backtrace_line(line, skip_textmate_conversion = false)

21
22
23
24
25
26
27
# File 'lib/rspec/core/formatters/text_mate_formatter.rb', line 21
def backtrace_line(line, skip_textmate_conversion=false)
  if skip_textmate_conversion
    super(line)
  else
    format_backtrace_line_for_textmate(super(line))
  end
end

- (Object) extra_failure_content(exception)

36
37
38
39
40
41
42
# File 'lib/rspec/core/formatters/text_mate_formatter.rb', line 36
def extra_failure_content(exception)
  require 'rspec/core/formatters/snippet_extractor'
  backtrace = exception.backtrace.map {|line| backtrace_line(line, :skip_textmate_conversion)}
  backtrace.compact!
  @snippet_extractor ||= SnippetExtractor.new
  "    <pre class=\"ruby\"><code>#{@snippet_extractor.snippet(backtrace)}</code></pre>"
end

- (Object) format_backtrace_line_for_textmate(line)

29
30
31
32
33
34
# File 'lib/rspec/core/formatters/text_mate_formatter.rb', line 29
def format_backtrace_line_for_textmate(line)
  return nil unless line
  CGI.escapeHTML(line).sub(/([^:]*\.e?rb):(\d*)/) do
    "<a href=\"txmt://open?url=file://#{File.expand_path($1)}&amp;line=#{$2}\">#{$1}:#{$2}</a> "
  end
end