123456789_123456789_123456789_123456789_123456789_

Class: RSpec::Core::ExampleStatusDumper Private

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: rspec-core/lib/rspec/core/example_status_persister.rb

Overview

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.

Class Method Summary

Instance Method Summary

Class Method Details

.dump(examples)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/example_status_persister.rb', line 144

def self.dump(examples)
  new(examples).dump
end

Instance Method Details

#column_widths (private)

[ GitHub ]

  
# File 'rspec-core/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

#dump

[ GitHub ]

  
# File 'rspec-core/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

#formatted_header_rows (private)

[ GitHub ]

  
# File 'rspec-core/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) (private)

[ GitHub ]

  
# File 'rspec-core/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 (private)

[ GitHub ]

  
# File 'rspec-core/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 (private)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/example_status_persister.rb', line 184

def headers
  @headers ||= @examples.first.keys
end

#rows (private)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/example_status_persister.rb', line 172

def rows
  @rows ||= @examples.map { |ex| ex.values_at(*headers) }
end