Class: RSpec::Core::Formatters::BaseTextFormatter
Constant Summary
Constants included
from Helpers
Helpers::DEFAULT_PRECISION, Helpers::SUB_SECOND_PRECISION
Instance Attribute Summary
#duration, #example_count, #example_group, #examples, #failed_examples, #failure_count, #output, #pending_count, #pending_examples
Instance Method Summary
collapse
#add_example_group, #example_failed, #example_group_finished, #example_group_started, #example_passed, #example_pending, #example_started, #format_backtrace, #initialize, #start, #start_dump, #stop
Methods included from Helpers
#format_seconds, #strip_trailing_zeroes
Instance Method Details
95
96
97
|
# File 'lib/rspec/core/formatters/base_text_formatter.rb', line 95
def close
output.close if IO === output && output != $stdout
end
|
#colorise_summary(summary) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/rspec/core/formatters/base_text_formatter.rb', line 47
def colorise_summary(summary)
if failure_count == 0
if pending_count > 0
yellow(summary)
else
green(summary)
end
else
red(summary)
end
end
|
#dump_failures ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/rspec/core/formatters/base_text_formatter.rb', line 13
def dump_failures
return if failed_examples.empty?
output.puts
output.puts "Failures:"
failed_examples.each_with_index do |example, index|
output.puts if index > 0
exception = example.execution_result[:exception_encountered]
short_padding = ' '
padding = ' '
if exception.is_a?(RSpec::Core::PendingExampleFixedError)
output.puts "#{short_padding}#{index.next}) #{example.full_description} FIXED"
output.puts "#{padding}Expected pending '#{example.metadata[:execution_result][:pending_message]}' to fail. No Error was raised."
else
output.puts "#{short_padding}#{index.next}) #{example.full_description}"
output.puts "#{padding}#{red("Failure/Error:")} #{red(read_failed_line(exception, example).strip)}"
exception.message.split("\n").each do |line|
output.puts "#{padding}#{red(line)}"
end
example.example_group.ancestors.push(example.example_group).each do |group|
if group.metadata[:shared_group_name]
output.puts "#{padding}Shared Example Group: \"#{group.metadata[:shared_group_name]}\" called from " +
"#{backtrace_line(group.metadata[:example_group][:location])}"
break
end
end
end
format_backtrace(exception.backtrace, example).each do |backtrace_info|
output.puts grey("#{padding}# #{backtrace_info}")
end
end
end
|
#dump_pending ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/rspec/core/formatters/base_text_formatter.rb', line 83
def dump_pending
unless pending_examples.empty?
output.puts
output.puts "Pending:"
pending_examples.each do |pending_example|
output.puts yellow(" #{pending_example.full_description}")
output.puts grey(" # #{pending_example.metadata[:execution_result][:pending_message]}")
output.puts grey(" # #{format_caller(pending_example.metadata[:location])}")
end
end
end
|
#dump_profile ⇒ Object
67
68
69
70
71
72
73
74
|
# File 'lib/rspec/core/formatters/base_text_formatter.rb', line 67
def dump_profile
sorted_examples = examples.sort_by { |example| example.execution_result[:run_time] }.reverse.first(10)
output.puts "\nTop #{sorted_examples.size} slowest examples:\n"
sorted_examples.each do |example|
output.puts " #{example.full_description}"
output.puts grey(" #{red(format_seconds(example.execution_result[:run_time]))} #{red("seconds")} #{format_caller(example.metadata[:location])}")
end
end
|
#dump_summary(duration, example_count, failure_count, pending_count) ⇒ Object
59
60
61
62
63
64
65
|
# File 'lib/rspec/core/formatters/base_text_formatter.rb', line 59
def dump_summary(duration, example_count, failure_count, pending_count)
super(duration, example_count, failure_count, pending_count)
dump_profile if profile_examples? && failure_count == 0
output.puts "\nFinished in #{format_seconds(duration)} seconds\n"
output.puts colorise_summary(summary_line(example_count, failure_count, pending_count))
end
|
#message(message) ⇒ Object
9
10
11
|
# File 'lib/rspec/core/formatters/base_text_formatter.rb', line 9
def message(message)
output.puts message
end
|
#summary_line(example_count, failure_count, pending_count) ⇒ Object
76
77
78
79
80
81
|
# File 'lib/rspec/core/formatters/base_text_formatter.rb', line 76
def summary_line(example_count, failure_count, pending_count)
summary = pluralize(example_count, "example")
summary << ", " << pluralize(failure_count, "failure")
summary << ", #{pending_count} pending" if pending_count > 0
summary
end
|