Sha256: 595ee1055c86e43f1ced3d45edf4c7c57eb82852ffe048cb8a870b2564f695f9

Contents?: true

Size: 1.68 KB

Versions: 10

Compression:

Stored size: 1.68 KB

Contents

require 'cgi'
require 'rspec/core/formatters/html_formatter'

module RSpec
  module Core
    module Formatters
      # Formats backtraces so they're clickable by TextMate
      class TextMateFormatter < HtmlFormatter
        class NonEscapingHtmlPrinter < RSpec::Core::Formatters::HtmlPrinter
          def print_example_failed(pending_fixed, description, run_time, failure_id, exception, extra_content, escape_backtrace = false)
            # Call implementation from superclass, but ignore `escape_backtrace` and always pass `false` instead.
            super(pending_fixed, description, run_time, failure_id, exception, extra_content, false)
          end
        end

        def initialize(output)
          super
          @printer = NonEscapingHtmlPrinter.new(output)
        end

        def backtrace_line(line, skip_textmate_conversion=false)
          if skip_textmate_conversion
            super(line)
          else
            format_backtrace_line_for_textmate(super(line))
          end
        end

        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

        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
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rspec-core-2.14.8/lib/rspec/core/formatters/text_mate_formatter.rb
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/rspec-core-2.14.8/lib/rspec/core/formatters/text_mate_formatter.rb
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/rspec-core-2.14.8/lib/rspec/core/formatters/text_mate_formatter.rb
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/rspec-core-2.14.8/lib/rspec/core/formatters/text_mate_formatter.rb
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/rspec-core-2.14.8/lib/rspec/core/formatters/text_mate_formatter.rb
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/rspec-core-2.14.8/lib/rspec/core/formatters/text_mate_formatter.rb
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/rspec-core-2.14.8/lib/rspec/core/formatters/text_mate_formatter.rb
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/rspec-core-2.14.8/lib/rspec/core/formatters/text_mate_formatter.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/rspec-core-2.14.8/lib/rspec/core/formatters/text_mate_formatter.rb
rspec-core-2.14.8 lib/rspec/core/formatters/text_mate_formatter.rb