class RspecN::Formatters::TableFormatter
Attributes
columns[RW]
Public Class Methods
new(runner:)
click to toggle source
# File lib/rspec_n/formatters/table_formatter.rb, line 8 def initialize(runner:) @runner = runner @columns = { "Run" => 7, "Start Time" => 21, "Finish Time" => 21, "Duration" => 12, "Seed" => 9, "Results" => 50 } @header_columns_string = padded_header_column_labels @table_width = @header_columns_string.size @format = "%m/%d %l:%M:%S %p" end
Public Instance Methods
observe() { || ... }
click to toggle source
# File lib/rspec_n/formatters/table_formatter.rb, line 23 def observe write_table_header yield write_conclusion end
show_post_run_info(run)
click to toggle source
# File lib/rspec_n/formatters/table_formatter.rb, line 34 def show_post_run_info(run) print pad_field("Finish Time", run.formatted_finish_time(@format)) print duration_field(run) print seed_field(run) puts result_count_field(run) end
show_pre_run_info(run)
click to toggle source
# File lib/rspec_n/formatters/table_formatter.rb, line 29 def show_pre_run_info(run) print pad_field("Run", run.iteration) print pad_field("Start Time", run.formatted_start_time(@format)) end
Private Instance Methods
duration_field(run)
click to toggle source
# File lib/rspec_n/formatters/table_formatter.rb, line 79 def duration_field(run) hms = convert_seconds_to_hms(run.duration_seconds) pad_field("Duration", hms) end
max_column_width_for(name)
click to toggle source
# File lib/rspec_n/formatters/table_formatter.rb, line 68 def max_column_width_for(name) columns[name] end
pad_field(column_name, value)
click to toggle source
# File lib/rspec_n/formatters/table_formatter.rb, line 72 def pad_field(column_name, value) max_width = max_column_width_for(column_name) value_size = value.to_s.remove_color.size pad_count = max_width - value_size value.to_s + (" " * pad_count) end
padded_header_column_label(name, width)
click to toggle source
# File lib/rspec_n/formatters/table_formatter.rb, line 59 def padded_header_column_label(name, width) right_padding = width - name.size name + (" " * right_padding) end
padded_header_column_labels()
click to toggle source
# File lib/rspec_n/formatters/table_formatter.rb, line 64 def padded_header_column_labels columns.collect { |name, max_width| padded_header_column_label(name, max_width) }.join end
result_color_symbol(run)
click to toggle source
# File lib/rspec_n/formatters/table_formatter.rb, line 93 def result_color_symbol(run) case run.status_string when "Pass", "Pass (Warnings)" then :green when "Fail" then :red else :yellow end end
result_count_field(run)
click to toggle source
# File lib/rspec_n/formatters/table_formatter.rb, line 88 def result_count_field(run) warning_part = run.has_warnings? ? " (Warnings)".colorize(:yellow) : "" run.result_count_string.colorize(result_color_symbol(run)) + warning_part end
seed_field(run)
click to toggle source
# File lib/rspec_n/formatters/table_formatter.rb, line 84 def seed_field(run) run.seed.nil? ? pad_field("Seed", "None") : pad_field("Seed", run.seed) end
write_conclusion()
click to toggle source
# File lib/rspec_n/formatters/table_formatter.rb, line 48 def write_conclusion puts "-" * @table_width puts "" puts "Total Duration: #{convert_seconds_to_hms(@runner.total_duration_seconds)}" puts "Avg Run Duration: #{convert_seconds_to_hms(@runner.avg_duration_seconds)}" puts "Runs Passed: #{@runner.total_passed.to_s.colorize(:green)}" puts "Runs Failed: #{@runner.total_failed.to_s.colorize(:red)}" puts "Runs Skipped: #{@runner.total_skipped}" puts "" end
write_table_header()
click to toggle source
# File lib/rspec_n/formatters/table_formatter.rb, line 43 def write_table_header puts @header_columns_string puts "-" * @table_width end