| 1 |
# Test results reporter for RubyMine IDE (http://www.jetbrains.com/ruby/) and |
| 2 |
# TeamCity(http://www.jetbrains.com/teamcity/) Continuous Integration Server |
| 3 |
|
| 4 |
begin |
| 5 |
require 'teamcity/runner_common' |
| 6 |
require 'teamcity/utils/service_message_factory' |
| 7 |
require 'teamcity/utils/runner_utils' |
| 8 |
require 'teamcity/utils/url_formatter' |
| 9 |
rescue LoadError |
| 10 |
require "minitest/reporters/default_reporter" |
| 11 |
|
| 12 |
# delegate to default reporter |
| 13 |
module Minitest |
| 14 |
module Reporters |
| 15 |
class RubyMineReporter < DefaultReporter |
| 16 |
def initialize(options = {}) |
| 17 |
super |
| 18 |
puts("====================================================================================================\n") |
| 19 |
puts("RubyMine reporter works only if it test was launched using RubyMine IDE or TeamCity CI server !!!\n") |
| 20 |
puts("====================================================================================================\n") |
| 21 |
puts("Using default results reporter...\n") |
| 22 |
end |
| 23 |
end |
| 24 |
end |
| 25 |
end |
| 26 |
else |
| 27 |
module Minitest |
| 28 |
module Reporters |
| 29 |
class RubyMineReporter < BaseReporter |
| 30 |
include ANSI::Code |
| 31 |
|
| 32 |
include ::Rake::TeamCity::RunnerCommon |
| 33 |
include ::Rake::TeamCity::RunnerUtils |
| 34 |
include ::Rake::TeamCity::Utils::UrlFormatter |
| 35 |
|
| 36 |
def start |
| 37 |
super |
| 38 |
puts('Started with run options %s' % options[:args]) |
| 39 |
puts |
| 40 |
|
| 41 |
# Setup test runner's MessageFactory |
| 42 |
set_message_factory(Rake::TeamCity::MessageFactory) |
| 43 |
log_test_reporter_attached |
| 44 |
|
| 45 |
# Report tests count: |
| 46 |
if ::Rake::TeamCity.is_in_idea_mode |
| 47 |
log(@message_factory.create_tests_count(total_count)) |
| 48 |
elsif ::Rake::TeamCity.is_in_buildserver_mode |
| 49 |
log(@message_factory.create_progress_message("Starting.. (#{total_count} tests)")) |
| 50 |
end |
| 51 |
end |
| 52 |
|
| 53 |
def report |
| 54 |
super |
| 55 |
|
| 56 |
puts('Finished in %.5fs' % total_time) |
| 57 |
print('%d tests, %d assertions, ' % [count, assertions]) |
| 58 |
print(red '%d failures, %d errors, ' % [failures, errors]) |
| 59 |
print(yellow '%d skips' % skips) |
| 60 |
puts |
| 61 |
end |
| 62 |
|
| 63 |
def record(test) |
| 64 |
super |
| 65 |
unless test.passed? |
| 66 |
with_result(test) do |exception_msg, backtrace| |
| 67 |
if test.skipped? |
| 68 |
log(@message_factory.create_test_ignored(test.name, exception_msg, backtrace)) |
| 69 |
elsif test.error? |
| 70 |
log(@message_factory.create_test_error(test.name, exception_msg, backtrace)) |
| 71 |
else |
| 72 |
log(@message_factory.create_test_failed(test.name, exception_msg, backtrace)) |
| 73 |
end |
| 74 |
end |
| 75 |
end |
| 76 |
log(@message_factory.create_test_finished(test.name, get_time_in_ms(test.time))) |
| 77 |
end |
| 78 |
|
| 79 |
alias_method :output, :io |
| 80 |
|
| 81 |
def before_suite(suite) |
| 82 |
fqn = suite.name |
| 83 |
log(@message_factory.create_suite_started(suite.name, location_from_ruby_qualified_name(fqn))) |
| 84 |
end |
| 85 |
|
| 86 |
def after_suite(suite) |
| 87 |
log(@message_factory.create_suite_finished(suite.name)) |
| 88 |
end |
| 89 |
|
| 90 |
def before_test(test) |
| 91 |
super |
| 92 |
location = test.class.instance_method(test.name).source_location |
| 93 |
log(@message_factory.create_test_started(test.name, "file://#{location[0]}:#{location[1]}")) |
| 94 |
end |
| 95 |
|
| 96 |
######### |
| 97 |
def log(msg) |
| 98 |
output.flush |
| 99 |
output.puts("\n#{msg}") |
| 100 |
output.flush |
| 101 |
|
| 102 |
# returns: |
| 103 |
msg |
| 104 |
end |
| 105 |
|
| 106 |
def with_result(test) |
| 107 |
exception = test.failure |
| 108 |
msg = exception.nil? ? "" : "#{exception.class.name}: #{exception.message}" |
| 109 |
backtrace = exception.nil? ? "" : filter_backtrace(exception.backtrace).join("\n") |
| 110 |
|
| 111 |
yield(msg, backtrace) |
| 112 |
end |
| 113 |
end |
| 114 |
end |
| 115 |
end |
| 116 |
end |