lib/gurke/reporters/team_city_reporter.rb in gurke-3.0.0 vs lib/gurke/reporters/team_city_reporter.rb in gurke-3.1.0

- old
+ new

@@ -3,104 +3,70 @@ module Gurke::Reporters # # The {TeamCityReporter} prints features, scenarios and # steps in a format parseable by TeamCity CI. # - class TeamCityReporter < NullReporter - attr_reader :io - def initialize(io = $stdout) - @io = io - end - + class TeamCityReporter < DefaultReporter def before_feature(feature) publish :testSuiteStarted, name: feature.name - io.puts " #{feature.description.split("\n").join("\n ")}" - io.puts + + super end def before_scenario(scenario) - @scenario = scenario + @status_reported = false + publish :testStarted, name: scenario.name - end - def start_background(*) - io.puts ' Background:' unless @background - - @background = true + super end - def end_background(*) - @background = false - end - - def before_step(step, *) - io.print ' ' if @background - io.print ' ' - io.print step.keyword - io.print step.name - end - - def after_step(step, *) - case step.state - when :pending then print_pending step - when :failed then print_failed step - when :success then print_braces 'success' - else print_braces 'skipped' - end - io.puts - io.flush - end - def after_scenario(scenario) publish :testFinished, name: scenario.name + + super end def after_feature(feature) publish :testSuiteFinished, name: feature.name - end - def after_features(features) - scenarios = features.map(&:scenarios).flatten - - example_count = scenarios.size - failure_count = scenarios.select(&:failed?).size - pending_count = scenarios.select(&:pending?).size - - io.puts " #{example_count} scenarios: " \ - "#{failure_count} failing, " \ - "#{pending_count} pending" - io.puts + super end - private + protected - def print_braces(str) - io.print " (#{str})" - end + def step_pending(step, *) + super - def print_pending(_step) - return if @pending == @scenario # only once per scenario - publish :testIgnored, - name: @scenario.name, + report :testIgnored, + name: step.scenario.name, message: 'Step definition missing' - @pending = @scenario end - def print_failed(step) - publish :testFailed, - name: @scenario.name, + def step_failed(step, *args) + super(step, *args, exception: false) + + report :testFailed, + name: step.scenario.name, message: step.exception.inspect, backtrace: step.exception.backtrace.join('\n') - @pending = @scenario - print_braces 'failure' - io.puts + print_exception(step.exception) + end - exout = format_exception(step.exception) - io.puts exout.map {|s| " #{s}\n" }.join + private + + def status_reported? + @status_reported end + def report(*args) + return if status_reported? + + publish(*args) + end + def publish(message_name, args) args = [] << message_name.to_s << escaped_array_of(args) args = args.flatten.reject(&:nil?) io.puts "##teamcity[#{args.join(' ')}]" @@ -116,12 +82,8 @@ if args.is_a? Hash args.map {|key, value| "#{key}='#{escape value.to_s}'" } else "'#{escape args}'" end - end - - def step_name(step) - step.keyword + step.name.gsub(/"(.*?)"/, '\0') end end end