File: tps_prof.rb

package info (click to toggle)
ruby-test-prof 1.5.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 660 kB
  • sloc: ruby: 6,064; makefile: 4
file content (46 lines) | stat: -rw-r--r-- 1,027 bytes parent folder | download
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
# frozen_string_literal: true

require "test_prof/tps_prof/profiler"
require "test_prof/tps_prof/reporter/text"

module TestProf
  # TPSProf shows top-N example group based on their tests-per-second value.
  #
  # Example:
  #
  #   TPS_PROF=10 rspec ...
  #
  module TPSProf
    class Configuration
      attr_accessor :top_count, :threshold, :reporter

      def initialize
        @top_count = ENV["TPS_PROF"].to_i
        @top_count = 10 if @top_count == 1
        @threshold = ENV.fetch("TPS_PROF_MIN", 10).to_i
        @reporter = resolve_reporter(ENV["TPS_PROF_FORMAT"])
      end

      private

      def resolve_reporter(format)
        # TODO: support other formats
        TPSProf::Reporter::Text.new
      end
    end

    class << self
      def config
        @config ||= Configuration.new
      end

      def configure
        yield config
      end
    end
  end
end

require "test_prof/tps_prof/rspec" if TestProf.rspec?
# TODO: Minitest support
# require "test_prof/tps_prof/minitest" if TestProf.minitest?