1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
module Blade::CI
extend self
include Blade::Component
def start
@completed_sessions = 0
@failures = []
Blade.subscribe("/results") do |details|
process_result(details)
end
end
private
def process_result(details)
if status = details[:status]
STDOUT.print status_dot(status)
if status == "fail"
@failures << details
end
end
if details[:completed]
process_completion
end
end
def process_completion
@completed_sessions += 1
if done?
EM.add_timer 2 do
display_failures
STDOUT.puts
exit_with_status_code
end
end
end
def status_dot(status)
Blade::TestResults::STATUS_DOTS[status]
end
def done?
@completed_sessions == (Blade.config.expected_sessions || 1)
end
def display_failures
@failures.each do |details|
STDERR.puts "\n\n#{status_dot(details[:status])} #{details[:name]} (#{Blade::Session.find(details[:session_id])})"
STDERR.puts details[:message]
end
end
def exit_with_status_code
exit @failures.any? ? 1 : 0
end
end
|