Class: Minitest::Test

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

Overview

:nodoc:

Defined Under Namespace

Classes: Focus

Constant Summary collapse

@@filtered_names =

:nodoc:

[]

Class Method Summary collapse

Class Method Details

.add_to_filter(name) ⇒ Object



10
11
12
# File 'lib/minitest/focus.rb', line 10

def self.add_to_filter name
  @@filtered_names << "#{self}##{name}"
end

.filtered_namesObject



14
15
16
# File 'lib/minitest/focus.rb', line 14

def self.filtered_names
  @@filtered_names
end

.focus(name = nil) ⇒ Object

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

class MyTest < Minitest::Test

  # direct approach
  focus def test_method1 # will run
    ...
  end

  # indirect approach
  focus
  def test_method2       # will run
    ...
  end

  def test_method3       # will NOT run
    ...
  end
end


40
41
42
43
44
45
46
# File 'lib/minitest/focus.rb', line 40

def self.focus name = nil
  if name then
    add_to_filter name
  else
    set_focus_trap
  end
end

.set_focus_trapObject

Sets a one-off method_added callback to set focus on the method defined next.



52
53
54
55
56
57
58
59
60
# File 'lib/minitest/focus.rb', line 52

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

  meta.send :define_method, :method_added do |name|
    add_to_filter name

    meta.send :remove_method, :method_added
  end
end