Sha256: 6fac3699e1045804a58812affb1691425b2a2b29d60e57ac0b5d4920531e6162

Contents?: true

Size: 972 Bytes

Versions: 4

Compression:

Stored size: 972 Bytes

Contents

# frozen_string_literal: true

require 'terminal-table'

# converts the examples array to a table string
class TableBuilder
  def initialize(examples)
    @examples = examples
  end

  def generate_table
    Terminal::Table.new do |t|
      t.headings = ['Test Case', 'Expected result', 'status']
      t.rows = map_examples(@examples)
      t.style = { border_left: false, border_right: false, border: :markdown }
    end
  end

  protected

  def map_examples(examples)
    examples.map { |example| map_example(example) }
  end

  def map_example(example)
    [
      example.metadata[:example_group][:full_description],
      example.description,
      execution_status(example)
    ]
  end

  def execution_status(example)
    puts example.execution_result.status
    case example.execution_result.status
    when :passed
      '✔️  Passed'
    when :failed
      '❌ Failed'
    when :pending
      '⚠️ Test case pending'
    else
      ''
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rspec_table_formatter-0.1.10 lib/table_builder.rb
rspec_table_formatter-0.1.9 lib/table_builder.rb
rspec_table_formatter-0.1.7 lib/table_builder.rb
rspec_table_formatter-0.1.6 lib/table_builder.rb