Class: TConsole::MiniTestHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/tconsole/minitest_handler.rb

Class Method Summary collapse

Class Method Details

.patch_minitestObject

We’re basically breaking MiniTest autorun here, since we want to manually run our tests and Rails relies on autorun

A big reason for the need for this is that we’re trying to work in the Rake environment rather than rebuilding all of the code in Rake just to get test prep happening correctly.



39
40
41
42
43
44
45
46
# File 'lib/tconsole/minitest_handler.rb', line 39

def self.patch_minitest
  ::MiniTest::Unit.class_eval do
    alias_method :old_run, :run
    def run(args = [])
      # do nothing
    end
  end
end

.preload_elementsObject

Preloads our element cache for autocompletion. Assumes tests are already loaded



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/tconsole/minitest_handler.rb', line 15

def self.preload_elements
  patch_minitest

  results = TConsole::TestResult.new

  suites = ::MiniTest::Unit::TestCase.test_suites
  suites.each do |suite|
    suite.test_methods.map do |method|
      id = results.add_element(suite, method)
    end
  end

  results

  patch_minitest
end

.setup(match_patterns, config) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/tconsole/minitest_handler.rb', line 3

def self.setup(match_patterns, config)
  # Make sure we have a recent version of minitest, and use it
  if ::MiniTest::Unit.respond_to?(:runner=)
    ::MiniTest::Unit.runner = TConsole::MiniTestUnit.new(match_patterns, config)
  else
    raise "MiniTest v#{MiniTest::Unit::VERSION} is not compatible with tconsole. Please load a more recent version of MiniTest"
  end

  ::MiniTest::Unit.runner
end