74 ### Called after all examples are run. Emit details for each failed example, |
74 ### Called after all examples are run. Emit details for each failed example, |
75 ### for Vim to fold. |
75 ### for Vim to fold. |
76 ### |
76 ### |
77 def dump_failures |
77 def dump_failures |
78 self.out "\n" unless @failures.empty? |
78 self.out "\n" unless @failures.empty? |
|
79 cwd = Regexp.new( Dir.pwd ) |
|
80 bt_regexp = /(.+?):(\d+)(|:\d+)/ |
79 |
81 |
80 @failures.each_with_index do |example, index| |
82 @failures.each_with_index do |example, index| |
81 desc = example.metadata[ :full_description ] |
83 desc = example.metadata[ :full_description ] |
82 exception = example.execution_result[ :exception ] |
84 exception = example.execution_result[ :exception ] |
83 file = line = nil |
85 file = line = nil |
84 |
86 |
85 if exception.backtrace.first =~ /(.*):(\d+)/ |
87 # remove files that are not in within the cwd. |
86 file, line = $1, $2.to_i |
88 # |
87 end |
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 |
88 self.out "FAILURE - #%d)" % [ index + 1 ] |
95 self.out "FAILURE - #%d)" % [ index + 1 ] |
89 self.out "%s:%d" % [ file, line ] |
96 self.out "%s:%d" % [ file, line ] if bt_file |
90 |
97 |
91 if RSpec::Core::PendingExampleFixedError === exception |
98 if exception.respond_to?( :pending_fixed? ) && exception.pending_fixed? |
92 self.out "%s FIXED" % [ desc ] |
99 self.out "%s FIXED" % [ desc ] |
93 self.out "Expected pending '%s' to fail. No error was raised." % [ |
100 self.out "Expected pending '%s' to fail. No error was raised." % [ |
94 example.metadata[ :execution_result ][ :pending_message ] |
101 example.metadata[ :execution_result ][ :pending_message ] |
95 ] |
102 ] |
96 else |
103 else |
178 description = metadata[ :description ] |
185 description = metadata[ :description ] |
179 return "| %s (%0.3fs" % [ description, duration ] |
186 return "| %s (%0.3fs" % [ description, duration ] |
180 end |
187 end |
181 end # SpeckyFormatter |
188 end # SpeckyFormatter |
182 |
189 |
|
190 |
|
191 ### Identical to the regular SpeckyFormatter, but it puts summary |
|
192 ### information at the bottom of the screen instead of the top, and just |
|
193 ### spits out rudamentary failure info. |
|
194 ### |
|
195 class SpeckyFormatterConsole < SpeckyFormatter |
|
196 def close |
|
197 puts "Failures:" unless @failures.empty? |
|
198 @failures.each do |test| |
|
199 metadata = test.metadata |
|
200 msg = "- %s\n %s\n %s:%d\n\n" % [ |
|
201 metadata[:full_description], |
|
202 test.exception.message, |
|
203 metadata[:file_path], |
|
204 metadata[:line_number] |
|
205 ] |
|
206 puts msg |
|
207 end |
|
208 output.puts @summary |
|
209 end |
|
210 end |
|
211 |