module SpecSelectorUtil::Format

The Format module contains methods used for simple text formatting, as well as methods that determine how specific list items will be formatted.

Constants

ESCAPE_CODES

Public Instance Methods

fail_count() click to toggle source
# File lib/spec_selector/format.rb, line 60
def fail_count
  red("FAIL: #{@fail_count}")
end
fetch_examples(item) click to toggle source
# File lib/spec_selector/format.rb, line 23
def fetch_examples(item)
  return [item] if example?(item)

  examples = item.examples
  return examples if @map[item.metadata[:block]] == examples

  examples.reject! { |ex| ex.execution_result.status.nil? }

  @map[item.metadata[:block]].each do |d|
    examples += fetch_examples(d)
  end

  examples
end
format_example(status, data) click to toggle source
# File lib/spec_selector/format.rb, line 76
def format_example(status, data)
  if %i[failed pending].include?(status)
    print_nonpassing_example(data)
  else
    print_passing_example
  end
end
format_list_item(item) click to toggle source
# File lib/spec_selector/format.rb, line 38
def format_list_item(item)
  description = lineage(item.metadata)
  data = example?(item) ? [item] : fetch_examples(item)
  included = item.metadata[:include]

  if @selected == item
    highlight(description, included)
  else
    green(description, included) if all_passed?(data)
    yellow(description, included) if any_pending?(data) && !any_failed?(data)
    red(description, included) if any_failed?(data)
  end
end
highlight(text, included = false) click to toggle source
# File lib/spec_selector/format.rb, line 64
def highlight(text, included = false)
  text += ' √' if included
  @output.puts "\e[1;7m#{text}\e[0m"
end
lineage(data) click to toggle source
# File lib/spec_selector/format.rb, line 69
def lineage(data)
  parent = parent_data(data)
  return data[:description] unless parent

  lineage(parent) + ' -> ' + data[:description]
end
pass_count() click to toggle source
# File lib/spec_selector/format.rb, line 52
def pass_count
  green("PASS: #{@pass_count}")
end
pending_count() click to toggle source
# File lib/spec_selector/format.rb, line 56
def pending_count
  yellow("PENDING: #{@pending_count}")
end
print_nonpassing_example(data) click to toggle source
print_passing_example() click to toggle source