class Gurke::Reporters::TeamCityReporter

The {TeamCityReporter} prints features, scenarios and steps in a format parseable by TeamCity CI.

Public Instance Methods

after_feature(feature) click to toggle source
# File lib/gurke/reporters/team_city_reporter.rb, line 42
def after_feature(feature)
  publish :testSuiteFinished, name: feature.name

  super
end
after_scenario(scenario) click to toggle source
# File lib/gurke/reporters/team_city_reporter.rb, line 21
def after_scenario(scenario)
  if scenario.failed?
    publish :testFailed,
      name: scenario.name,
      message: scenario.exception.inspect,
      backtrace: scenario.exception.backtrace.join('\n')
  elsif scenario.pending?
    publish :testIgnored,
      name: scenario.name,
      message: 'Step definition missing'
  elsif scenario.aborted?
    publish :testIgnored,
      name: scenario.name,
      message: 'Aborted.'
  end

  publish :testFinished, name: scenario.name

  super
end
before_feature(feature) click to toggle source
# File lib/gurke/reporters/team_city_reporter.rb, line 9
def before_feature(feature)
  publish :testSuiteStarted, name: feature.name

  super
end
before_scenario(scenario) click to toggle source
# File lib/gurke/reporters/team_city_reporter.rb, line 15
def before_scenario(scenario)
  publish :testStarted, name: scenario.name

  super
end

Private Instance Methods

escape(string) click to toggle source
# File lib/gurke/reporters/team_city_reporter.rb, line 57
def escape(string)
  string.gsub(/(\||'|\r|\n|\u0085|\u2028|\u2029|\[|\])/, '|$1')
end
escaped_array_of(args) click to toggle source
# File lib/gurke/reporters/team_city_reporter.rb, line 61
def escaped_array_of(args)
  return [] if args.nil?

  if args.is_a? Hash
    args.map {|key, value| "#{key}='#{escape value.to_s}'" }
  else
    "'#{escape args}'"
  end
end
publish(message_name, args) click to toggle source
# File lib/gurke/reporters/team_city_reporter.rb, line 50
def publish(message_name, args)
  args = [] << message_name.to_s << escaped_array_of(args)
  args = args.flatten.reject(&:nil?)

  io.puts "##teamcity[#{args.join(' ')}]"
end