Created
May 17, 2013 19:21
-
-
Save os97673/5601330 to your computer and use it in GitHub Desktop.
Draft of new minitest reporter for RubyMine.
To make it work, place it in minitest directory in your load path (e.g.<project root>/minitest/rm_reporter_plugin.rb)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
begin | |
require 'teamcity/runner_common' | |
require 'teamcity/utils/service_message_factory' | |
require 'teamcity/utils/runner_utils' | |
require 'teamcity/utils/url_formatter' | |
rescue LoadError | |
MiniTest::Unit.runner.output.puts("====================================================================================================\n") | |
MiniTest::Unit.runner.output.puts("RubyMine reporter works only if it test was launched using RubyMine IDE or TeamCity CI server !!!\n") | |
MiniTest::Unit.runner.output.puts("====================================================================================================\n") | |
MiniTest::Unit.runner.output.puts("Using default results reporter...\n") | |
else | |
module Minitest | |
def self.plugin_rm_reporter_options(opts, options) | |
end | |
def self.plugin_rm_reporter_init(options) | |
Minitest.reporter.reporters.clear | |
self.reporter << MyReporter.new(options) | |
end | |
class MyReporter | |
include ::Rake::TeamCity::RunnerCommon | |
include ::Rake::TeamCity::RunnerUtils | |
include ::Rake::TeamCity::Utils::UrlFormatter | |
def initialize(options = {}) | |
@passed = true | |
self.io= options[:io] | |
@test_count, @assertion_count, @failures, @errors, @skips = 0, 0, 0, 0, 0 | |
end | |
def start | |
io.puts 'Started' | |
io.puts | |
# Setup test runner's MessageFactory | |
set_message_factory(Rake::TeamCity::MessageFactory) | |
log_test_reporter_attached() | |
# Report tests count: | |
# todo: calc test count | |
self.test_count = 1 | |
if ::Rake::TeamCity.is_in_idea_mode | |
log(@message_factory.create_tests_count(test_count)) | |
elsif ::Rake::TeamCity.is_in_buildserver_mode | |
log(@message_factory.create_progress_message("Starting.. (#{test_count} tests)")) | |
end | |
@suites_start_time = Time.now | |
end | |
def report | |
total_time = Time.now - @suites_start_time | |
io.puts('Finished in %.5fs' % total_time) | |
io.print('%d tests, %d assertions, ' % [test_count, assertion_count]) | |
io.print('%d failures, %d errors, ' % [failures, errors]) | |
io.print('%d skips' % skips) | |
io.puts | |
end | |
def record(result) | |
@assertion_count += result.assertions | |
if result.skipped? | |
@skips += 1 | |
with_result(result) do |exception_msg, backtrace| | |
log(@message_factory.create_test_ignored(result, exception_msg, backtrace)) | |
end | |
end | |
if not result.passed? and result.failure.class == Assertion | |
@failures += 1 | |
with_result(result) do |exception_msg, backtrace| | |
log(@message_factory.create_test_failed(result, exception_msg, backtrace)) | |
end | |
end | |
if not result.passed? and result.failure.class == UnexpectedError | |
@errors += 1 | |
with_result(result) do |exception_msg, backtrace| | |
log(@message_factory.create_test_error(result, exception_msg, backtrace)) | |
end | |
end | |
if result.passed? | |
fqn = "#{result.class}.#{result.name}" | |
log(@message_factory.create_test_started(result, minitest_test_location(fqn))) | |
duration_ms = get_time_in_ms(result.time) | |
log(@message_factory.create_test_finished(result, duration_ms.nil? ? 0 : duration_ms)) | |
end | |
end | |
def passed? | |
@passed | |
end | |
private | |
attr_accessor :io, :test_count, :assertion_count, :failures, :errors, :skips | |
def log(msg) | |
io.flush | |
io.puts("\n#{msg}") | |
io.flush | |
# returns: | |
msg | |
end | |
def minitest_test_location(fqn) | |
return nil if (fqn.nil?) | |
"ruby_minitest_qn://#{fqn}" | |
end | |
def with_result(result) | |
exception = result.failure | |
msg = exception.nil? ? '' : "#{exception.class.name}: #{exception.message}" | |
backtrace = exception.nil? ? '' : Minitest::filter_backtrace(exception.backtrace).join("\n") | |
yield(msg, backtrace) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment