Class: CucumberGithubFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber_github_formatter.rb

Overview

Main formatter class

Constant Summary collapse

VERSION =
'0.1.0'

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ CucumberGithubFormatter

Returns a new instance of CucumberGithubFormatter.



7
8
9
# File 'lib/cucumber_github_formatter.rb', line 7

def initialize(config)
  config.on_event :test_case_finished, &method(:print_github_message)
end

Instance Method Details

rubocop:disable Metrics/MethodLength,Metrics/AbcSize



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cucumber_github_formatter.rb', line 11

def print_github_message(event) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
  if event.result.failed?
    status = 'error'
    message = 'failed: ' + event.result.exception.message.to_s
    file, line = event.result.exception.backtrace.last.split(':')
  elsif event.result.pending?
    status = 'warning'
    message = 'pending'
    file = event.test_case.location.file
    line = event.test_case.location.lines.to_s
  else
    return
  end

  name = event.test_case.name
  puts "::#{status} file=#{file},line=#{line}::#{name} #{message}"
end