Sha256: acc1324072a41b72a70ae5ece38ee1ba4d36bfc332038e86a49f7dde7b6a4347

Contents?: true

Size: 2 KB

Versions: 33

Compression:

Stored size: 2 KB

Contents

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

      def io
        all_reporters.first.io unless all_reporters.empty?
        @options[:io]
      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|
          runnable.runnable_methods.find_all { |m|
            filter === m || filter === "#{runnable}##{m}"
          }.size
        }.inject(:+)
      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

33 entries across 26 versions & 8 rubygems

Version Path
josufst_palindrome-0.2.0 vendor/cache/gems/minitest-reporters-1.2.0/lib/minitest/minitest_reporter_plugin.rb
josufst_palindrome-0.2.0 vendor/cache/ruby/2.6.0/gems/minitest-reporters-1.2.0/lib/minitest/minitest_reporter_plugin.rb
josufst_palindrome-0.1.1 vendor/cache/ruby/2.6.0/gems/minitest-reporters-1.2.0/lib/minitest/minitest_reporter_plugin.rb
josufst_palindrome-0.1.1 vendor/cache/gems/minitest-reporters-1.2.0/lib/minitest/minitest_reporter_plugin.rb
hirohig_palindrome-0.2.0 vendor/bundle/ruby/2.6.0/gems/minitest-reporters-1.2.0/lib/minitest/minitest_reporter_plugin.rb
hirohig_palindrome-0.1.0 vendor/bundle/ruby/2.6.0/gems/minitest-reporters-1.2.0/lib/minitest/minitest_reporter_plugin.rb
cspeezy_palindrome-0.3.0 path/ruby/2.6.0/gems/minitest-reporters-1.2.0/lib/minitest/minitest_reporter_plugin.rb
cspeezy_palindrome-0.2.0 path/ruby/2.6.0/gems/minitest-reporters-1.2.0/lib/minitest/minitest_reporter_plugin.rb
cspeezy_palindrome-0.1.0 path/ruby/2.6.0/gems/minitest-reporters-1.2.0/lib/minitest/minitest_reporter_plugin.rb
steenfest_palindrome-0.1.2 ruby/2.5/gems/minitest-reporters-1.2.0/lib/minitest/minitest_reporter_plugin.rb
steenfest_palindrome-0.1.1b ruby/2.5/gems/minitest-reporters-1.2.0/lib/minitest/minitest_reporter_plugin.rb
dmurphy_palindrome-0.1.0 vendor/cache/ruby/2.3.0/gems/dmurphy_palindrome-0.1.0/vendor/cache/ruby/2.3.0/gems/minitest-reporters-1.2.0/lib/minitest/minitest_reporter_plugin.rb
dmurphy_palindrome-0.1.0 vendor/cache/ruby/2.3.0/gems/minitest-reporters-1.2.0/lib/minitest/minitest_reporter_plugin.rb
lgrgic_palindrome_detector-0.2.0 vendor/cache/gems/lgrgic_palindrome_detector-0.1.0/vendor/cache/gems/minitest-reporters-1.2.0/lib/minitest/minitest_reporter_plugin.rb
lgrgic_palindrome_detector-0.2.0 vendor/cache/gems/minitest-reporters-1.2.0/lib/minitest/minitest_reporter_plugin.rb
lgrgic_palindrome_detector-0.1.0 vendor/cache/gems/minitest-reporters-1.2.0/lib/minitest/minitest_reporter_plugin.rb
wfrey_palindrome-0.3.0 vendor/bundle/ruby/2.3.0/gems/wfrey_palindrome-0.1.0/vendor/bundle/ruby/2.3.0/gems/minitest-reporters-1.2.0/lib/minitest/minitest_reporter_plugin.rb
wfrey_palindrome-0.3.0 vendor/bundle/ruby/2.3.0/gems/minitest-reporters-1.2.0/lib/minitest/minitest_reporter_plugin.rb
wfrey_palindrome-0.2.0 vendor/bundle/ruby/2.3.0/gems/wfrey_palindrome-0.1.0/vendor/bundle/ruby/2.3.0/gems/minitest-reporters-1.2.0/lib/minitest/minitest_reporter_plugin.rb
wfrey_palindrome-0.2.0 vendor/bundle/ruby/2.3.0/gems/minitest-reporters-1.2.0/lib/minitest/minitest_reporter_plugin.rb