Sha256: 5ed717551a2a9ecd3f44571daaff52a7448d716236f193e5745631f5daacf894

Contents?: true

Size: 1.82 KB

Versions: 4

Compression:

Stored size: 1.82 KB

Contents

module Minitest
  module Reporters
    class DelegateReporter
      def initialize(reporters, options = {})
        @reporters = reporters
        @options = options
        @all_reporters = nil
      end

      def start
        all_reporters.each(&:start)
      end

      def record(result)
        all_reporters.each do |reporter|
          reporter.record result
        end
      end

      def report
        all_reporters.each(&:report)
      end

      def passed?
        all_reporters.all?(&:passed?)
      end

      private
      # stolen from minitest self.run
      def total_count(options)
        filter = options[:filter] || '/./'
        filter = Regexp.new $1 if filter =~ /\/(.*)\//

        Minitest::Runnable.runnables.map(&:runnable_methods).flatten.find_all { |m|
          filter === m || filter === "#{self}##{m}"
        }.size
      end

      def all_reporters
        @all_reporters ||= init_all_reporters
      end

      def init_all_reporters
        return @reporters unless defined?(Minitest::Reporters.reporters) && Minitest::Reporters.reporters
        (Minitest::Reporters.reporters + guard_reporter(@reporters)).each do |reporter|
          reporter.io = @options[:io]
          if reporter.respond_to?(:add_defaults)
            reporter.add_defaults(@options.merge(:total_count => total_count(@options)))
          end
        end
      end

      def guard_reporter(reporters)
        guards = Array(reporters.detect { |r| r.class.name == "Guard::Minitest::Reporter" })
        return guards unless ENV['RM_INFO']

        warn 'RM_INFO is set thus guard reporter has been dropped' unless guards.empty?
        []
      end
    end
  end

  class << self
    def plugin_minitest_reporter_init(options)
      reporter.reporters = [Minitest::Reporters::DelegateReporter.new(reporter.reporters, options)]
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
minitest-reporters-1.1.4 lib/minitest/minitest_reporter_plugin.rb
minitest-reporters-1.1.3 lib/minitest/minitest_reporter_plugin.rb
minitest-reporters-1.1.2 lib/minitest/minitest_reporter_plugin.rb
minitest-reporters-1.1.1 lib/minitest/minitest_reporter_plugin.rb