class RspecGithubActionsFormatter

Constants

VERSION

Public Instance Methods

dump_failures(notification) click to toggle source
Calls superclass method
# File lib/rspec_github_actions_formatter.rb, line 45
def dump_failures(notification)
  if notification.failed_examples.length > 0
    super
    @output << failed_examples_output(notification)
  end
end
dump_pending(notification) click to toggle source
Calls superclass method
# File lib/rspec_github_actions_formatter.rb, line 38
def dump_pending(notification)
  if notification.pending_examples.length > 0
    super
    @output << pending_examples_output(notification)
  end
end
example_failed(notification) click to toggle source
Calls superclass method
# File lib/rspec_github_actions_formatter.rb, line 32
def example_failed(notification)
  super

  split_progress_into_lines(notification)
end
example_passed(notification) click to toggle source
Calls superclass method
# File lib/rspec_github_actions_formatter.rb, line 20
def example_passed(notification)
  super

  split_progress_into_lines(notification)
end
example_pending(notification) click to toggle source
Calls superclass method
# File lib/rspec_github_actions_formatter.rb, line 26
def example_pending(notification)
  super

  split_progress_into_lines(notification)
end
example_started(_notification) click to toggle source
# File lib/rspec_github_actions_formatter.rb, line 16
def example_started(_notification)
  @examples_executed += 1
end
start(example_count) click to toggle source
Calls superclass method
# File lib/rspec_github_actions_formatter.rb, line 8
def start(example_count)
  @example_count = example_count.count
  @examples_executed = 0
  @tests_per_line = terminal_width - progress_display_width(@example_count)

  super
end

Private Instance Methods

build_examples_output(output) click to toggle source
# File lib/rspec_github_actions_formatter.rb, line 93
def build_examples_output(output)
  output.join("\n")
end
escape_newlines(message) click to toggle source
# File lib/rspec_github_actions_formatter.rb, line 97
def escape_newlines(message)
  message.gsub('\n', '\\n')
end
failed_example_output(example) click to toggle source

Extracts the full_description, location and formats the message of each example exception

# File lib/rspec_github_actions_formatter.rb, line 85
def failed_example_output(example)
  execution_result = example.execution_result
  message = escape_newlines(execution_result.exception.message)
  file, line = file_and_line(example.location)

  "::error file=#{file},line=#{line},#{message}"
end
failed_examples_output(notification) click to toggle source

Loops through all of the failed examples and rebuilds the exception message

# File lib/rspec_github_actions_formatter.rb, line 77
def failed_examples_output(notification)
  failed_examples_output = notification.failed_examples.map do |example|
    failed_example_output example
  end
  build_examples_output(failed_examples_output)
end
file_and_line(location) click to toggle source
# File lib/rspec_github_actions_formatter.rb, line 101
def file_and_line(location)
  location.delete_prefix("./").split(":")
end
pending_example_output(example) click to toggle source
# File lib/rspec_github_actions_formatter.rb, line 68
def pending_example_output(example)
  execution_result = example.execution_result
  message = execution_result.pending_message
  file, line = file_and_line(example.location)

  "::warning file=#{file},line=#{line},#{message}"
end
pending_examples_output(notification) click to toggle source
# File lib/rspec_github_actions_formatter.rb, line 61
def pending_examples_output(notification)
  pending_examples_output = notification.pending_examples.map do |example|
    pending_example_output(example)
  end
  build_examples_output(pending_examples_output)
end
progress_display(executed_examples, total_examples) click to toggle source
# File lib/rspec_github_actions_formatter.rb, line 112
def progress_display(executed_examples, total_examples)
  max_width = total_examples.to_s.size
  sprintf " [%#{max_width}d / %#{max_width}d]", executed_examples, total_examples
end
progress_display_width(example_count) click to toggle source
# File lib/rspec_github_actions_formatter.rb, line 117
def progress_display_width(example_count)
  progress_display(example_count, example_count).size
end
split_progress_into_lines(_notification) click to toggle source
# File lib/rspec_github_actions_formatter.rb, line 54
def split_progress_into_lines(_notification)
  if @examples_executed % @tests_per_line == 0 || @examples_executed == @example_count
    output.print progress_display(@examples_executed, @example_count)
    output.print "\n"
  end
end
terminal_width() click to toggle source

If it says less than 80 columns, don't accept it. GitHub Actions seems to set it to something silly like 40 characters, and I haven't yet figured out why. Help welcome!

# File lib/rspec_github_actions_formatter.rb, line 108
def terminal_width
  [`tput cols`.to_i, 80].max
end