Module: Minitest
- Defined in:
- lib/minitest.rb,
lib/minitest/mock.rb,
lib/minitest/test.rb,
lib/minitest/unit.rb,
lib/minitest/parallel.rb,
lib/minitest/benchmark.rb,
lib/minitest/benchmark.rb,
lib/minitest/assertions.rb,
lib/minitest/pride_plugin.rb
Overview
:nodoc:
Defined Under Namespace
Modules: Assertions, Expectations, Guard, Parallel Classes: AbstractReporter, Assertion, BacktraceFilter, BenchSpec, Benchmark, CompositeReporter, Mock, PrideIO, PrideLOL, ProgressReporter, Reporter, Runnable, Skip, Spec, StatisticsReporter, SummaryReporter, Test, UnexpectedError, Unit
Constant Summary collapse
- VERSION =
:nodoc:
"5.8.3"
- ENCS =
:nodoc:
"".respond_to? :encoding
- @@after_run =
[]
Class Method Summary collapse
-
.__run(reporter, options) ⇒ Object
Internal run method.
-
.after_run(&block) ⇒ Object
A simple hook allowing you to run a block of code after everything is done running.
-
.autorun ⇒ Object
Registers Minitest to run at process exit.
- .clock_time ⇒ Object
-
.filter_backtrace(bt) ⇒ Object
:nodoc:.
-
.init_plugins(options) ⇒ Object
:nodoc:.
-
.load_plugins ⇒ Object
:nodoc:.
-
.plugin_pride_init(options) ⇒ Object
:nodoc:.
-
.plugin_pride_options(opts, _options) ⇒ Object
:nodoc:.
-
.process_args(args = []) ⇒ Object
:nodoc:.
-
.run(args = []) ⇒ Object
This is the top-level run method.
-
.run_one_method(klass, method_name) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#attr_accessor ⇒ Object
Names of known extension plugins.
Class Method Details
.__run(reporter, options) ⇒ Object
Internal run method. Responsible for telling all Runnable sub-classes to run.
NOTE: this method is redefined in parallel_each.rb, which is loaded if a Runnable calls parallelize_me!.
146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/minitest.rb', line 146 def self.__run reporter, suites = Runnable.runnables.shuffle parallel, serial = suites.partition { |s| s.test_order == :parallel } # If we run the parallel tests before the serial tests, the parallel tests # could run in parallel with the serial tests. This would be bad because # the serial tests won't lock around Reporter#record. Run the serial tests # first, so that after they complete, the parallel tests will lock when # recording results. serial.map { |suite| suite.run reporter, } + parallel.map { |suite| suite.run reporter, } end |
.after_run(&block) ⇒ Object
A simple hook allowing you to run a block of code after everything is done running. Eg:
Minitest.after_run { p $debugging_info }
67 68 69 |
# File 'lib/minitest.rb', line 67 def self.after_run &block @@after_run << block end |
.autorun ⇒ Object
Registers Minitest to run at process exit
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/minitest.rb', line 45 def self.autorun at_exit { next if $! and not ($!.kind_of? SystemExit and $!.success?) exit_code = nil at_exit { @@after_run.reverse_each(&:call) exit exit_code || false } exit_code = Minitest.run ARGV } unless @@installed_at_exit @@installed_at_exit = true end |
.clock_time ⇒ Object
787 788 789 |
# File 'lib/minitest.rb', line 787 def self.clock_time Process.clock_gettime Process::CLOCK_MONOTONIC end |
.filter_backtrace(bt) ⇒ Object
:nodoc:
225 226 227 |
# File 'lib/minitest.rb', line 225 def self.filter_backtrace bt # :nodoc: backtrace_filter.filter bt end |
.init_plugins(options) ⇒ Object
:nodoc:
71 72 73 74 75 76 |
# File 'lib/minitest.rb', line 71 def self.init_plugins # :nodoc: self.extensions.each do |name| msg = "plugin_#{name}_init" send msg, if self.respond_to? msg end end |
.load_plugins ⇒ Object
:nodoc:
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/minitest.rb', line 78 def self.load_plugins # :nodoc: return unless self.extensions.empty? seen = {} require "rubygems" unless defined? Gem Gem.find_files("minitest/*_plugin.rb").each do |plugin_path| name = File.basename plugin_path, "_plugin.rb" next if seen[name] seen[name] = true require plugin_path self.extensions << name end end |
.plugin_pride_init(options) ⇒ Object
:nodoc:
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/minitest/pride_plugin.rb', line 10 def self.plugin_pride_init # :nodoc: if PrideIO.pride? then klass = ENV["TERM"] =~ /^xterm|-256color$/ ? PrideLOL : PrideIO io = klass.new [:io] self.reporter.reporters.grep(Minitest::Reporter).each do |rep| rep.io = io if rep.io.tty? end end end |
.plugin_pride_options(opts, _options) ⇒ Object
:nodoc:
4 5 6 7 8 |
# File 'lib/minitest/pride_plugin.rb', line 4 def self. opts, # :nodoc: opts.on "-p", "--pride", "Pride. Show your testing pride!" do PrideIO.pride! end end |
.process_args(args = []) ⇒ Object
:nodoc:
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/minitest.rb', line 159 def self.process_args args = [] # :nodoc: = { :io => $stdout, } orig_args = args.dup OptionParser.new do |opts| opts. = "minitest options:" opts.version = Minitest::VERSION opts.on "-h", "--help", "Display this help." do puts opts exit end desc = "Sets random seed. Also via env. Eg: SEED=n rake" opts.on "-s", "--seed SEED", Integer, desc do |m| [:seed] = m.to_i end opts.on "-v", "--verbose", "Verbose. Show progress processing files." do [:verbose] = true end opts.on "-n", "--name PATTERN", "Filter run on /regexp/ or string." do |a| [:filter] = a end unless extensions.empty? opts.separator "" opts.separator "Known extensions: #{extensions.join(", ")}" extensions.each do |meth| msg = "plugin_#{meth}_options" send msg, opts, if self.respond_to?(msg) end end begin opts.parse! args rescue OptionParser::InvalidOption => e puts puts e puts puts opts exit 1 end orig_args -= args end unless [:seed] then srand [:seed] = (ENV["SEED"] || srand).to_i % 0xFFFF orig_args << "--seed" << [:seed].to_s end srand [:seed] [:args] = orig_args.map { |s| s =~ /[\s|&<>$()]/ ? s.inspect : s }.join " " end |
.run(args = []) ⇒ Object
This is the top-level run method. Everything starts from here. It tells each Runnable sub-class to run, and each of those are responsible for doing whatever they do.
The overall structure of a run looks like this:
Minitest.autorun
Minitest.run(args)
Minitest.__run(reporter, )
Runnable.runnables.each
runnable.run(reporter, )
self.runnable_methods.each
self.run_one_method(self, runnable_method, reporter)
Minitest.run_one_method(klass, runnable_method)
klass.new(runnable_method).run
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/minitest.rb', line 113 def self.run args = [] self.load_plugins = process_args args reporter = CompositeReporter.new reporter << SummaryReporter.new([:io], ) reporter << ProgressReporter.new([:io], ) self.reporter = reporter # this makes it available to plugins self.init_plugins self.reporter = nil # runnables shouldn't depend on the reporter, ever self.parallel_executor.start if parallel_executor.respond_to?(:start) reporter.start begin __run reporter, rescue Interrupt warn "Interrupted. Exiting..." end self.parallel_executor.shutdown reporter.report reporter.passed? end |
.run_one_method(klass, method_name) ⇒ Object
:nodoc:
780 781 782 783 784 |
# File 'lib/minitest.rb', line 780 def self.run_one_method klass, method_name # :nodoc: result = klass.new(method_name).run raise "#{klass}#run _must_ return self" unless klass === result result end |
Instance Method Details
#attr_accessor ⇒ Object
Names of known extension plugins.
22 |
# File 'lib/minitest.rb', line 22 mc.send :attr_accessor, :parallel_executor |