specky/ruby/specky_formatter.rb
author Mahlon E. Smith <mahlon@martini.nu>
Fri, 24 Dec 2010 20:01:10 -0800
branchvim-stuff
changeset 21 cd1f3381c1ed
parent 19 763cef799c74
child 22 ed72213b1788
permissions -rw-r--r--
Emit file and line for failure source (use gF to jump straight to it!). Show context lines for exception source. Put spec summary run at the top of the screen. Small documentation fixes.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     1
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     2
require 'rspec/core/formatters/base_text_formatter'
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     3
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     4
### SpeckyFormatter: A basic RSpec 2.x text formatter, to be used
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     5
### with the 'Specky' vim plugin (or from the command line, if you
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     6
### dig it over the default 'documentation' format!)
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     7
###
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     8
### rspec -r /path/to/this/specky_formatter.rb -f SpeckyFormatter specs
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     9
###
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    10
class SpeckyFormatter < RSpec::Core::Formatters::BaseTextFormatter
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    11
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    12
	def initialize( *args )
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    13
		super
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    14
		@indent_level  = 0
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    15
		@failure_index = 0
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    16
		@failures      = []
21
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
    17
		@txt           = ''
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
    18
		@summary       = ''
19
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    19
	end
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    20
21
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
    21
19
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    22
	########################################################################
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    23
	### R S P E C  H O O K S
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    24
	########################################################################
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    25
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    26
	### Example group hook -- increase indentation, emit description
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    27
	###
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    28
	def example_group_started( example_group )
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    29
		self.out '+', '-' * (example_group.description.length + 2), '+'
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    30
		self.out '| ', example_group.description, ' |'
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    31
		self.out '+', '-' * (example_group.description.length + 2), '+'
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    32
		@indent_level += 1
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    33
	end
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    34
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    35
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    36
	### Example group hook -- decrease indentation
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    37
	###
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    38
	def example_group_finished( example_group )
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    39
		@indent_level -= 1
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    40
	end
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    41
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    42
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    43
	### Called on example success
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    44
	###
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    45
	def example_passed( example )
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    46
		msg = self.format_example( example )
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    47
		msg << ')'
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    48
		self.out msg
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    49
	end
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    50
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    51
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    52
	### Called on a pending example
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    53
	###
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    54
	def example_pending( example )
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    55
		msg = self.format_example( example )
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    56
		pending_msg = example.metadata[ :execution_result ][ :pending_message ]
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    57
		msg << ", PENDING%s)" % [ ": #{pending_msg}" || '' ]
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    58
		self.out msg
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    59
	end
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    60
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    61
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    62
	### Called on example failure
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    63
	###
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    64
	def example_failed( example )
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    65
		@failure_index += 1
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    66
		msg = self.format_example( example )
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    67
		msg << ", FAILED - #%d)" % [ @failure_index ]
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    68
		self.out msg
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    69
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    70
		@failures << example
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    71
	end
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    72
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    73
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    74
	### Called after all examples are run.  Emit details for each failed example,
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    75
	### for Vim to fold.
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    76
	###
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    77
	def dump_failures
21
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
    78
		self.out "\n" unless @failures.empty?
19
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    79
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    80
		@failures.each_with_index do |example, index|
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    81
			desc      = example.metadata[ :full_description ]
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    82
			exception = example.execution_result[ :exception ]
21
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
    83
			file = line = nil
19
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    84
21
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
    85
			if exception.backtrace.first =~ /(.*):(\d+)/
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
    86
				file, line = $1, $2.to_i
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
    87
			end
19
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    88
			self.out "FAILURE - #%d)" % [ index + 1 ]
21
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
    89
			self.out "%s:%d" % [ file, line ]
19
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    90
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    91
			if RSpec::Core::PendingExampleFixedError === exception
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    92
				self.out "%s FIXED" % [ desc ]
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    93
				self.out "Expected pending '%s' to fail.  No error was raised." % [
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    94
					example.metadata[ :execution_result ][ :pending_message ]
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    95
				]
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    96
			else
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    97
				self.out desc
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    98
				self.out "Failure/Error: %s" %  [ read_failed_line( exception, example).strip ]
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    99
				exception.message.split("\n").each {|l| self.out l}
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   100
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   101
				# logic taken from the base class
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   102
				example.example_group.ancestors.push(example.example_group).each do |group|
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   103
					if group.metadata[:shared_group_name]
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   104
						self.out "Shared Example Group: \"#{group.metadata[:shared_group_name]}\" called from " +
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   105
							"#{backtrace_line(group.metadata[:example_group][:location])}"
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   106
						break
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   107
					end
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   108
				end
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   109
			end
21
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   110
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   111
			self.out exception_source( file, line ) if file && line
19
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   112
		end
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   113
	end
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   114
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   115
21
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   116
	### Emit the source of the exception, with context lines.
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   117
	###
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   118
	def exception_source( file, line )
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   119
		context = ''
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   120
		low, high = line - 3, line + 3
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   121
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   122
		File.open( file ).each_with_index do |cline, i|
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   123
			cline.chomp!.rstrip!
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   124
			next unless i >= low && i <= high
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   125
			context << "  %s%4d: %s\n" % [ ( i == line ? '>>' : ' |' ), i, cline ]
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   126
		end
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   127
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   128
		return context
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   129
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   130
	rescue
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   131
		'Unable to parse exception context lines.'
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   132
	end
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   133
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   134
19
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   135
	### Emit summary data for all examples.
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   136
	###
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   137
	def dump_summary( duration, example_count, failure_count, pending_count )
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   138
		succeeded = example_count - failure_count - pending_count
21
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   139
		@summary << "+%s+\n" % [ '-' * 49 ]
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   140
		@summary << "|%s-- Summary --%s|\n" % [ ' ' * 18, ' ' * 18 ]
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   141
		@summary << "+----------+-----------+--------+---------+-------+\n"
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   142
		@summary << "| Duration | Succeeded | Failed | Pending | Total |\n"
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   143
		@summary << "+----------+-----------+--------+---------+-------+\n"
19
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   144
21
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   145
		@summary << "| %7ss | %9s | %6s | %7s | %5s |\n" % [
19
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   146
			"%0.3f" % duration, succeeded, failure_count,
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   147
			pending_count, example_count
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   148
		]
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   149
21
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   150
		@summary << "+----------+-----------+--------+---------+-------+\n\n"
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   151
	end
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   152
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   153
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   154
	### End of run.  Dump it all out!
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   155
	###
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   156
	def close
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   157
		output.puts @summary
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   158
		output.puts @txt
19
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   159
	end
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   160
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   161
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   162
	#########
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   163
	protected
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   164
	#########
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   165
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   166
	### Send a string to the output IO object, after indentation.
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   167
	###
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   168
	def out( *msg )
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   169
		msg = msg.join
21
cd1f3381c1ed Emit file and line for failure source (use gF to jump straight to it!).
Mahlon E. Smith <mahlon@martini.nu>
parents: 19
diff changeset
   170
		@txt << "%s%s\n" % [ '  ' * @indent_level, msg ]
19
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   171
	end
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   172
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   173
	### Format the basic example information, along with the run duration.
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   174
	###
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   175
	def format_example( example )
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   176
		metadata    = example.metadata
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   177
		duration    = metadata[ :execution_result ][ :run_time ]
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   178
		description = metadata[ :description ]
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   179
		return "| %s (%0.3fs" % [ description, duration ]
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   180
	end
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   181
end # SpeckyFormatter
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   182