class RSpec::Core::ExampleStatusDumper

Dumps a list of hashes in a pretty, human readable format for later parsing. The hashes are expected to have symbol keys and string values, and each hash should have the same set of keys. @private

Public Class Methods

dump(examples) click to toggle source
# File lib/rspec/core/example_status_persister.rb, line 144
def self.dump(examples)
  new(examples).dump
end
new(examples) click to toggle source
# File lib/rspec/core/example_status_persister.rb, line 148
def initialize(examples)
  @examples = examples
end

Public Instance Methods

dump() click to toggle source
# File lib/rspec/core/example_status_persister.rb, line 152
def dump
  return nil if @examples.empty?
  (formatted_header_rows + formatted_value_rows).join("\n") << "\n"
end

Private Instance Methods

column_widths() click to toggle source
# File lib/rspec/core/example_status_persister.rb, line 188
def column_widths
  @column_widths ||= begin
    value_sets = rows.transpose

    headers.each_with_index.map do |header, index|
      values = value_sets[index] << header.to_s
      values.map(&:length).max
    end
  end
end
formatted_header_rows() click to toggle source
# File lib/rspec/core/example_status_persister.rb, line 159
def formatted_header_rows
  @formatted_header_rows ||= begin
    dividers = column_widths.map { |w| "-" * w }
    [formatted_row_from(headers.map(&:to_s)), formatted_row_from(dividers)]
  end
end
formatted_row_from(row_values) click to toggle source
# File lib/rspec/core/example_status_persister.rb, line 176
def formatted_row_from(row_values)
  padded_values = row_values.each_with_index.map do |value, index|
    value.ljust(column_widths[index])
  end

  padded_values.join(" | ") << " |"
end
formatted_value_rows() click to toggle source
# File lib/rspec/core/example_status_persister.rb, line 166
def formatted_value_rows
  @formatted_value_rows ||= rows.map do |row|
    formatted_row_from(row)
  end
end
headers() click to toggle source
# File lib/rspec/core/example_status_persister.rb, line 184
def headers
  @headers ||= @examples.first.keys
end
rows() click to toggle source
# File lib/rspec/core/example_status_persister.rb, line 172
def rows
  @rows ||= @examples.map { |ex| ex.values_at(*headers) }
end