Class: Minitest::Test

Inherits:
Object
  • Object
show all
Defined in:
lib/minitest/focus5.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Focus

Constant Summary collapse

@@filtered_names =

:nodoc:

[]

Class Method Summary collapse

Class Method Details

.focusObject

Focus on the next test defined. Cumulative. Equivalent to running with command line arg: -n /test_name|…/

class MyTest < MiniTest::Unit::TestCase
  ...
  focus
  def test_pass; ... end # this one will run
  ...
end


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/minitest/focus5.rb', line 19

def self.focus
  meta = class << self; self; end

  meta.send :define_method, :method_added do |name|
    @@filtered_names << "#{self}##{name}"
    filter = "/^(#{Regexp.union(@@filtered_names).source})$/"

    index = ARGV.index("-n")
    unless index then
      index = ARGV.size
      ARGV << "-n"
    end

    ARGV[index + 1] = filter

    meta.send :remove_method, :method_added
  end
end