Base for all of RSpec's built-in formatters. See RSpec::Core::Formatters::BaseFormatter to learn more about all of the methods called by the reporter.
@see RSpec::Core::Formatters::BaseFormatter @see RSpec::Core::Reporter
# File lib/rspec/core/formatters/base_text_formatter.rb, line 125 def close output.close if IO === output && output != $stdout end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 142 def color_code_for(code_or_symbol) if VT100_COLOR_CODES.include?(code_or_symbol) code_or_symbol else VT100_COLORS.fetch(code_or_symbol) do color_code_for(:white) end end end
@api public
Colorizes the output red for failure, yellow for pending, and green otherwise.
@param [String] string
# File lib/rspec/core/formatters/base_text_formatter.rb, line 35 def colorise_summary(summary) if failure_count > 0 color(summary, RSpec.configuration.failure_color) elsif pending_count > 0 color(summary, RSpec.configuration.pending_color) else color(summary, RSpec.configuration.success_color) end end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 152 def colorize(text, code_or_symbol) "\e[#{color_code_for(code_or_symbol)}m#{text}\e[0m" end
@api public
Outputs commands which can be used to re-run failed examples.
# File lib/rspec/core/formatters/base_text_formatter.rb, line 57 def dump_commands_to_rerun_failed_examples return if failed_examples.empty? output.puts output.puts("Failed examples:") output.puts failed_examples.each do |example| output.puts(failure_color("rspec #{RSpec::Core::Metadata::relative_path(example.location)}") + " " + detail_color("# #{example.full_description}")) end end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 18 def dump_failures return if failed_examples.empty? output.puts output.puts "Failures:" failed_examples.each_with_index do |example, index| output.puts pending_fixed?(example) ? dump_pending_fixed(example, index) : dump_failure(example, index) dump_backtrace(example) end end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 102 def dump_pending unless pending_examples.empty? output.puts output.puts "Pending:" pending_examples.each do |pending_example| output.puts pending_color(" #{pending_example.full_description}") output.puts detail_color(" # #{pending_example.execution_result[:pending_message]}") output.puts detail_color(" # #{format_caller(pending_example.location)}") if pending_example.execution_result[:exception] && RSpec.configuration.show_failures_in_pending_blocks? dump_failure_info(pending_example) dump_backtrace(pending_example) end end end end
@api public
Outputs the slowest examples in a report when using `–profile COUNT` (default 10).
# File lib/rspec/core/formatters/base_text_formatter.rb, line 72 def dump_profile number_of_examples = RSpec.configuration.profile_examples sorted_examples = examples.sort_by {|example| example.execution_result[:run_time] }.reverse.first(number_of_examples) total, slows = [examples, sorted_examples].map {|exs| exs.inject(0.0) {|i, e| i + e.execution_result[:run_time] }} time_taken = slows / total percentage = '%.1f' % ((time_taken.nan? ? 0.0 : time_taken) * 100) output.puts "\nTop #{sorted_examples.size} slowest examples (#{format_seconds(slows)} seconds, #{percentage}% of total time):\n" sorted_examples.each do |example| output.puts " #{example.full_description}" output.puts detail_color(" #{failure_color(format_seconds(example.execution_result[:run_time]))} #{failure_color("seconds")} #{format_caller(example.location)}") end end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 45 def dump_summary(duration, example_count, failure_count, pending_count) super(duration, example_count, failure_count, pending_count) dump_profile if profile_examples? output.puts "\nFinished in #{format_duration(duration)}\n" output.puts colorise_summary(summary_line(example_count, failure_count, pending_count)) dump_commands_to_rerun_failed_examples end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 14 def message(message) output.puts message end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 119 def seed(number) output.puts output.puts "Randomized with seed #{number}" output.puts end
@api public
Outputs summary with number of examples, failures and pending.
# File lib/rspec/core/formatters/base_text_formatter.rb, line 95 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
# File lib/rspec/core/formatters/base_text_formatter.rb, line 205 def blue(text) RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#blue", "#fixed_color", "3.0") color(text, :blue) end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 158 def bold(text) color_enabled? ? "\e[1m#{text}\e[0m" : text end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 162 def color(text, color_code) color_enabled? ? colorize(text, color_code) : text end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 215 def cyan(text) RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#cyan", "#detail_color", "3.0") color(text, :cyan) end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 186 def default_color(text) color(text, RSpec.configuration.default_color) end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 182 def detail_color(text) color(text, RSpec.configuration.detail_color) end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 166 def failure_color(text) color(text, RSpec.configuration.failure_color) end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 178 def fixed_color(text) color(text, RSpec.configuration.fixed_color) end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 195 def green(text) RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#green", "#success_color", "3.0") color(text, :green) end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 229 def long_padding ' ' end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 210 def magenta(text) RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#magenta", nil, "3.0") color(text, :magenta) end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 174 def pending_color(text) color(text, RSpec.configuration.pending_color) end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 190 def red(text) RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#red", "#failure_color", "3.0") color(text, :red) end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 225 def short_padding ' ' end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 170 def success_color(text) color(text, RSpec.configuration.success_color) end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 220 def white(text) RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#white", "#default_color", "3.0") color(text, :white) end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 200 def yellow(text) RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#yellow", "#pending_color", "3.0") color(text, :yellow) end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 239 def dump_backtrace(example) format_backtrace(example.execution_result[:exception].backtrace, example).each do |backtrace_info| output.puts detail_color("#{long_padding}# #{backtrace_info}") end end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 254 def dump_failure(example, index) output.puts "#{short_padding}#{index.next}) #{example.full_description}" dump_failure_info(example) end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 259 def dump_failure_info(example) exception = example.execution_result[:exception] exception_class_name = exception_class_name_for(exception) output.puts "#{long_padding}#{failure_color("Failure/Error:")} #{failure_color(read_failed_line(exception, example).strip)}" output.puts "#{long_padding}#{failure_color(exception_class_name)}:" unless exception_class_name =~ /RSpec/ exception.message.to_s.split("\n").each { |line| output.puts "#{long_padding} #{failure_color(line)}" } if exception.message if shared_group = find_shared_group(example) dump_shared_failure_info(shared_group) end end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 245 def dump_pending_fixed(example, index) output.puts "#{short_padding}#{index.next}) #{example.full_description} FIXED" output.puts fixed_color("#{long_padding}Expected pending '#{example.metadata[:execution_result][:pending_message]}' to fail. No Error was raised.") end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 271 def exception_class_name_for(exception) name = exception.class.name.to_s name ="(anonymous error class)" if name == '' name end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 235 def format_caller(caller_info) backtrace_line(caller_info.to_s.split(':in `block').first) end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 286 def group_and_parent_groups(example) example.example_group.parent_groups + [example.example_group] end
# File lib/rspec/core/formatters/base_text_formatter.rb, line 250 def pending_fixed?(example) example.execution_result[:exception].pending_fixed? end