Module: TestProf

Extended by:
Logging
Defined in:
lib/test_prof/core.rb,
lib/test_prof/utils.rb,
lib/test_prof/logging.rb,
lib/test_prof/vernier.rb,
lib/test_prof/version.rb,
lib/test_prof/tag_prof.rb,
lib/test_prof/tps_prof.rb,
lib/test_prof/ruby_prof.rb,
lib/test_prof/before_all.rb,
lib/test_prof/event_prof.rb,
lib/test_prof/stack_prof.rb,
lib/test_prof/any_fixture.rb,
lib/test_prof/cops/inject.rb,
lib/test_prof/factory_bot.rb,
lib/test_prof/memory_prof.rb,
lib/test_prof/rspec_stamp.rb,
lib/test_prof/utils/rspec.rb,
lib/test_prof/factory_prof.rb,
lib/test_prof/rspec_dissect.rb,
lib/test_prof/vernier/rspec.rb,
lib/test_prof/factory_doctor.rb,
lib/test_prof/tag_prof/rspec.rb,
lib/test_prof/tps_prof/rspec.rb,
lib/test_prof/any_fixture/dsl.rb,
lib/test_prof/factory_default.rb,
lib/test_prof/recipes/logging.rb,
lib/test_prof/ruby_prof/rspec.rb,
lib/test_prof/tag_prof/result.rb,
lib/test_prof/any_fixture/dump.rb,
lib/test_prof/event_prof/rspec.rb,
lib/test_prof/factory_all_stub.rb,
lib/test_prof/stack_prof/rspec.rb,
lib/test_prof/memory_prof/rspec.rb,
lib/test_prof/rspec_stamp/rspec.rb,
lib/test_prof/tps_prof/profiler.rb,
lib/test_prof/event_prof/monitor.rb,
lib/test_prof/ext/float_duration.rb,
lib/test_prof/rspec_stamp/parser.rb,
lib/test_prof/utils/html_builder.rb,
lib/test_prof/event_prof/profiler.rb,
lib/test_prof/ext/string_truncate.rb,
lib/test_prof/memory_prof/printer.rb,
lib/test_prof/memory_prof/tracker.rb,
lib/test_prof/rspec_dissect/rspec.rb,
lib/test_prof/factory_doctor/rspec.rb,
lib/test_prof/recipes/rspec/sample.rb,
lib/test_prof/tps_prof/reporter/text.rb,
lib/test_prof/any_fixture/dump/digest.rb,
lib/test_prof/any_fixture/dump/sqlite.rb,
lib/test_prof/ext/array_bsearch_index.rb,
lib/test_prof/ext/string_parameterize.rb,
lib/test_prof/recipes/minitest/sample.rb,
lib/test_prof/recipes/rspec/let_it_be.rb,
lib/test_prof/utils/sized_ordered_set.rb,
lib/test_prof/event_prof/custom_events.rb,
lib/test_prof/ext/active_record_refind.rb,
lib/test_prof/ext/factory_bot_strategy.rb,
lib/test_prof/recipes/rspec/before_all.rb,
lib/test_prof/ruby_prof/rspec_exclusions.rb,
lib/test_prof/any_fixture/dump/postgresql.rb,
lib/test_prof/recipes/minitest/before_all.rb,
lib/test_prof/memory_prof/tracker/rss_tool.rb,
lib/test_prof/rspec_dissect/collectors/let.rb,
lib/test_prof/any_fixture/dump/base_adapter.rb,
lib/test_prof/rspec_dissect/collectors/base.rb,
lib/test_prof/factory_prof/fabrication_patch.rb,
lib/test_prof/factory_prof/factory_bot_patch.rb,
lib/test_prof/memory_prof/tracker/linked_list.rb,
lib/test_prof/rspec_dissect/collectors/before.rb,
lib/test_prof/factory_doctor/fabrication_patch.rb,
lib/test_prof/factory_doctor/factory_bot_patch.rb,
lib/test_prof/before_all/adapters/active_record.rb,
lib/test_prof/factory_default/fabrication_patch.rb,
lib/test_prof/factory_default/factory_bot_patch.rb,
lib/test_prof/factory_all_stub/factory_bot_patch.rb,
lib/test_prof/memory_prof/printer/number_to_human.rb,
lib/test_prof/factory_prof/factory_builders/fabrication.rb,
lib/test_prof/factory_prof/factory_builders/factory_bot.rb

Overview

:nodoc: all

Defined Under Namespace

Modules: AnyFixture, ArrayBSearchIndex, BeforeAll, Cops, EventProf, Ext, FactoryAllStub, FactoryBotStrategy, FactoryDefault, FactoryDoctor, FactoryProf, FloatDuration, LetItBe, Logging, MemoryProf, MinitestSample, RSpecDissect, RSpecStamp, RSpecWorldSamplePatch, Rails, RubyProf, StackProf, StringParameterize, StringTruncate, TPSProf, TagProf, Utils, Vernier Classes: Configuration

Constant Summary collapse

VERSION =
"1.4.2"
FACTORY_GIRL_NAMES =
{"factory_bot" => "::FactoryBot", "factory_girl" => "::FactoryGirl"}.freeze

Constants included from Logging

Logging::COLORS

Class Method Summary collapse

Methods included from Logging

log

Class Method Details

.activate(env_var, val = nil) ⇒ Object

Run block only if provided env var is present and equal to the provided value (if any). Contains workaround for applications using Spring.



100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/test_prof/core.rb', line 100

def activate(env_var, val = nil)
  if spring?
    notify_spring_detected
    ::Spring.after_fork do
      activate!(env_var, val) do
        notify_spring_activate env_var
        yield
      end
    end
  else
    activate!(env_var, val) { yield }
  end
end

.artifact_path(filename) ⇒ Object

Return a path to store artifact



120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/test_prof/core.rb', line 120

def artifact_path(filename)
  create_artifact_dir

  with_timestamps(
    ::File.join(
      config.output_dir,
      with_report_suffix(
        filename
      )
    )
  )
end

.asset_path(filename) ⇒ Object

Return absolute path to asset



115
116
117
# File 'lib/test_prof/core.rb', line 115

def asset_path(filename)
  ::File.expand_path(filename, ::File.join(::File.dirname(__FILE__), "..", "..", "assets"))
end

.configObject



53
54
55
# File 'lib/test_prof/core.rb', line 53

def config
  @config ||= Configuration.new
end

.configure {|config| ... } ⇒ Object

Yields:



57
58
59
# File 'lib/test_prof/core.rb', line 57

def configure
  yield config
end

.create_artifact_dirObject



133
134
135
# File 'lib/test_prof/core.rb', line 133

def create_artifact_dir
  FileUtils.mkdir_p(config.output_dir)[0]
end

.dry_run?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/test_prof/core.rb', line 78

def dry_run?
  rspec? && ::RSpec.configuration.dry_run?
end

.minitest?Boolean

Returns true if we’re inside Minitest

Returns:

  • (Boolean)


67
68
69
# File 'lib/test_prof/core.rb', line 67

def minitest?
  defined?(Minitest)
end

.nowObject

Returns the current process time



83
84
85
# File 'lib/test_prof/core.rb', line 83

def now
  Process.clock_gettime_for_test_prof(Process::CLOCK_MONOTONIC)
end

.require(gem_name, msg = nil) ⇒ Object

Require gem and shows a custom message if it fails to load



89
90
91
92
93
94
95
# File 'lib/test_prof/core.rb', line 89

def require(gem_name, msg = nil)
  Kernel.require gem_name
  block_given? ? yield : true
rescue LoadError
  log(:error, msg) if msg
  false
end

.rspec?Boolean

Returns true if we’re inside RSpec

Returns:

  • (Boolean)


62
63
64
# File 'lib/test_prof/core.rb', line 62

def rspec?
  defined?(RSpec::Core)
end

.spring?Boolean

Returns true if Spring is used and not disabled

Returns:

  • (Boolean)


72
73
74
75
76
# File 'lib/test_prof/core.rb', line 72

def spring?
  # See https://github.com/rails/spring/blob/577cf01f232bb6dbd0ade7df2df2ac209697e741/lib/spring/binstub.rb
  disabled = ENV["DISABLE_SPRING"]
  defined?(::Spring::Application) && (disabled.nil? || disabled.empty? || disabled == "0")
end