author | Mahlon E. Smith <mahlon@martini.nu> |
Sat, 16 Jan 2016 11:31:53 -0800 | |
branch | vim-stuff |
changeset 29 | a0e6ddfadf82 |
parent 28 | specky/ruby/specky_formatter.rb@2b198f0a86fe |
permissions | -rw-r--r-- |
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? |
22 | 79 |
cwd = Regexp.new( Dir.pwd ) |
80 |
bt_regexp = /(.+?):(\d+)(|:\d+)/ |
|
19
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
81 |
|
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
82 |
@failures.each_with_index do |example, index| |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
83 |
desc = example.metadata[ :full_description ] |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
84 |
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
|
85 |
file = line = nil |
19
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
86 |
|
22 | 87 |
# remove files that are not in within the cwd. |
88 |
# |
|
89 |
# this isn't optimal, but it does stay within specky's notion of |
|
90 |
# running it from within the project directory, and makes sure we don't |
|
91 |
# inadvertently display code from rspec itself. |
|
92 |
# |
|
93 |
bt_file = exception.backtrace.find { |line| line =~ bt_regexp && line =~ cwd } |
|
94 |
file, line = $1, $2.to_i if bt_file =~ bt_regexp |
|
19
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
95 |
self.out "FAILURE - #%d)" % [ index + 1 ] |
22 | 96 |
self.out "%s:%d" % [ file, line ] if bt_file |
19
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
97 |
|
22 | 98 |
if exception.respond_to?( :pending_fixed? ) && exception.pending_fixed? |
19
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
99 |
self.out "%s FIXED" % [ desc ] |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
100 |
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
|
101 |
example.metadata[ :execution_result ][ :pending_message ] |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
102 |
] |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
103 |
else |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
104 |
self.out desc |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
105 |
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
|
106 |
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
|
107 |
|
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
108 |
# logic taken from the base class |
28 | 109 |
if shared_group = find_shared_group(example) |
110 |
self.out "Shared Example Group: \"#{shared_group.metadata[:shared_group_name]}\" called from " + |
|
111 |
"#{backtrace_line(shared_group.metadata[:example_group][:location])}" |
|
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 |
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
|
114 |
|
22 | 115 |
self.out exception_source( file, line-1 ) if file && line |
19
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
116 |
end |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
117 |
end |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
118 |
|
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
119 |
|
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
|
120 |
### 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
|
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 |
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
|
123 |
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
|
124 |
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
|
125 |
|
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 |
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
|
127 |
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
|
128 |
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
|
129 |
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
|
130 |
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
|
131 |
|
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 |
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
|
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 |
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
|
135 |
'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
|
136 |
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
|
137 |
|
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
|
138 |
|
19
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
139 |
### Emit summary data for all examples. |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
140 |
### |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
141 |
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
|
142 |
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
|
143 |
@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
|
144 |
@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
|
145 |
@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
|
146 |
@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
|
147 |
@summary << "+----------+-----------+--------+---------+-------+\n" |
19
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
148 |
|
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
|
149 |
@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
|
150 |
"%0.3f" % duration, succeeded, failure_count, |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
151 |
pending_count, example_count |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
152 |
] |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
153 |
|
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
|
154 |
@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
|
155 |
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
|
156 |
|
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 |
|
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 |
### 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
|
159 |
### |
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
|
160 |
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
|
161 |
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
|
162 |
output.puts @txt |
19
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
163 |
end |
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 |
######### |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
167 |
protected |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
168 |
######### |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
169 |
|
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
170 |
### 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
|
171 |
### |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
172 |
def out( *msg ) |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
173 |
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
|
174 |
@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
|
175 |
end |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
176 |
|
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
177 |
### 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
|
178 |
### |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
179 |
def format_example( example ) |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
180 |
metadata = example.metadata |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
181 |
duration = metadata[ :execution_result ][ :run_time ] |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
182 |
description = metadata[ :description ] |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
183 |
return "| %s (%0.3fs" % [ description, duration ] |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
184 |
end |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
185 |
end # SpeckyFormatter |
763cef799c74
Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
186 |
|
22 | 187 |
|
188 |
### Identical to the regular SpeckyFormatter, but it puts summary |
|
189 |
### information at the bottom of the screen instead of the top, and just |
|
23
050dd6dcf346
Mimic the Progress formatter for console status feedback.
Mahlon E. Smith <mahlon@martini.nu>
parents:
22
diff
changeset
|
190 |
### spits out rudamentary failure info. Mimics the progress |
050dd6dcf346
Mimic the Progress formatter for console status feedback.
Mahlon E. Smith <mahlon@martini.nu>
parents:
22
diff
changeset
|
191 |
### formatter for status feedback |
22 | 192 |
### |
193 |
class SpeckyFormatterConsole < SpeckyFormatter |
|
23
050dd6dcf346
Mimic the Progress formatter for console status feedback.
Mahlon E. Smith <mahlon@martini.nu>
parents:
22
diff
changeset
|
194 |
|
050dd6dcf346
Mimic the Progress formatter for console status feedback.
Mahlon E. Smith <mahlon@martini.nu>
parents:
22
diff
changeset
|
195 |
def example_passed( ex ); print '.'; end |
24
38db5185d698
Don't forget to super() so the failures are emitted after the spec run.
Mahlon E. Smith <mahlon@martini.nu>
parents:
23
diff
changeset
|
196 |
def example_failed( ex ); print 'F'; super; end |
23
050dd6dcf346
Mimic the Progress formatter for console status feedback.
Mahlon E. Smith <mahlon@martini.nu>
parents:
22
diff
changeset
|
197 |
def example_pending( ex ); print '*'; end |
050dd6dcf346
Mimic the Progress formatter for console status feedback.
Mahlon E. Smith <mahlon@martini.nu>
parents:
22
diff
changeset
|
198 |
|
22 | 199 |
def close |
23
050dd6dcf346
Mimic the Progress formatter for console status feedback.
Mahlon E. Smith <mahlon@martini.nu>
parents:
22
diff
changeset
|
200 |
puts |
22 | 201 |
puts "Failures:" unless @failures.empty? |
202 |
@failures.each do |test| |
|
203 |
metadata = test.metadata |
|
204 |
msg = "- %s\n %s\n %s:%d\n\n" % [ |
|
205 |
metadata[:full_description], |
|
206 |
test.exception.message, |
|
207 |
metadata[:file_path], |
|
208 |
metadata[:line_number] |
|
209 |
] |
|
210 |
puts msg |
|
211 |
end |
|
212 |
output.puts @summary |
|
213 |
end |
|
214 |
end |
|
215 |