PageRenderTime 53ms CodeModel.GetById 12ms app.highlight 37ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/bundle/jruby/2.1/gems/rspec-core-2.14.8/lib/rspec/core/formatters/html_formatter.rb

https://github.com/delowong/logstash
Ruby | 155 lines | 124 code | 25 blank | 6 comment | 4 complexity | a847706426e4c09bfa11f70917004c34 MD5 | raw file
  1require 'rspec/core/formatters/base_text_formatter'
  2require 'rspec/core/formatters/html_printer'
  3
  4module RSpec
  5  module Core
  6    module Formatters
  7      class HtmlFormatter < BaseTextFormatter
  8
  9        def initialize(output)
 10          super(output)
 11          @example_group_number = 0
 12          @example_number = 0
 13          @header_red = nil
 14          @printer = HtmlPrinter.new(output)
 15        end
 16
 17        private
 18        def method_missing(m, *a, &b)
 19          # no-op
 20        end
 21
 22        public
 23        def message(message)
 24        end
 25
 26        # The number of the currently running example_group
 27        def example_group_number
 28          @example_group_number
 29        end
 30
 31        # The number of the currently running example (a global counter)
 32        def example_number
 33          @example_number
 34        end
 35
 36        def start(example_count)
 37          super(example_count)
 38          @printer.print_html_start
 39          @printer.flush
 40        end
 41
 42        def example_group_started(example_group)
 43          super(example_group)
 44          @example_group_red = false
 45          @example_group_number += 1
 46
 47          unless example_group_number == 1
 48            @printer.print_example_group_end
 49          end
 50          @printer.print_example_group_start( example_group_number, example_group.description, example_group.parent_groups.size )
 51          @printer.flush
 52        end
 53
 54        def start_dump
 55          @printer.print_example_group_end
 56          @printer.flush
 57        end
 58
 59        def example_started(example)
 60          super(example)
 61          @example_number += 1
 62        end
 63
 64        def example_passed(example)
 65          @printer.move_progress(percent_done)
 66          @printer.print_example_passed( example.description, example.execution_result[:run_time] )
 67          @printer.flush
 68        end
 69
 70        def example_failed(example)
 71          super(example)
 72
 73          unless @header_red
 74            @header_red = true
 75            @printer.make_header_red
 76          end
 77
 78          unless @example_group_red
 79            @example_group_red = true
 80            @printer.make_example_group_header_red(example_group_number)
 81          end
 82
 83          @printer.move_progress(percent_done)
 84
 85          exception = example.metadata[:execution_result][:exception]
 86          exception_details = if exception
 87            {
 88              :message => exception.message,
 89              :backtrace => format_backtrace(exception.backtrace, example).join("\n")
 90            }
 91          else
 92            false
 93          end
 94          extra = extra_failure_content(exception)
 95
 96          @printer.print_example_failed(
 97            example.execution_result[:pending_fixed],
 98            example.description,
 99            example.execution_result[:run_time],
100            @failed_examples.size,
101            exception_details,
102            (extra == "") ? false : extra,
103            true
104          )
105          @printer.flush
106        end
107
108        def example_pending(example)
109
110          @printer.make_header_yellow unless @header_red
111          @printer.make_example_group_header_yellow(example_group_number) unless @example_group_red
112          @printer.move_progress(percent_done)
113          @printer.print_example_pending( example.description, example.metadata[:execution_result][:pending_message] )
114          @printer.flush
115        end
116
117        # Override this method if you wish to output extra HTML for a failed spec. For example, you
118        # could output links to images or other files produced during the specs.
119        #
120        def extra_failure_content(exception)
121          require 'rspec/core/formatters/snippet_extractor'
122          backtrace = exception.backtrace.map {|line| backtrace_line(line)}
123          backtrace.compact!
124          @snippet_extractor ||= SnippetExtractor.new
125          "    <pre class=\"ruby\"><code>#{@snippet_extractor.snippet(backtrace)}</code></pre>"
126        end
127
128        def percent_done
129          result = 100.0
130          if @example_count > 0
131            result = (((example_number).to_f / @example_count.to_f * 1000).to_i / 10.0).to_f
132          end
133          result
134        end
135
136        def dump_failures
137        end
138
139        def dump_pending
140        end
141
142        def dump_summary(duration, example_count, failure_count, pending_count)
143          @printer.print_summary(
144            dry_run?,
145            duration,
146            example_count,
147            failure_count,
148            pending_count
149          )
150          @printer.flush
151        end
152      end
153    end
154  end
155end