Class: TConsole::MiniTestHandler
- Inherits:
-
Object
- Object
- TConsole::MiniTestHandler
- Defined in:
- lib/tconsole/minitest_handler.rb
Instance Attribute Summary collapse
-
#interrupted ⇒ Object
Returns the value of attribute interrupted.
Class Method Summary collapse
-
.patch_minitest ⇒ Object
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.
-
.preload_elements ⇒ Object
Preloads our element cache for autocompletion.
Instance Method Summary collapse
-
#initialize(config) ⇒ MiniTestHandler
constructor
A new instance of MiniTestHandler.
- #match_and_run(match_patterns, config) ⇒ Object
Constructor Details
#initialize(config) ⇒ MiniTestHandler
Returns a new instance of MiniTestHandler.
7 8 9 10 11 12 |
# File 'lib/tconsole/minitest_handler.rb', line 7 def initialize(config) @reporter = ::TConsole::MinitestReporter.new @reporter.tc_results.suite_counts = config.cached_suite_counts @reporter.tc_results.elements = config.cached_elements @interrupted = false end |
Instance Attribute Details
#interrupted ⇒ Object
Returns the value of attribute interrupted.
5 6 7 |
# File 'lib/tconsole/minitest_handler.rb', line 5 def interrupted @interrupted end |
Class Method Details
.patch_minitest ⇒ Object
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.
80 81 82 83 84 85 86 87 88 |
# File 'lib/tconsole/minitest_handler.rb', line 80 def self.patch_minitest Minitest.class_eval do class << self alias_method :old_run, :run def run(args = []) end end end end |
.preload_elements ⇒ Object
Preloads our element cache for autocompletion. Assumes tests are already loaded
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/tconsole/minitest_handler.rb', line 62 def self.preload_elements patch_minitest results = TConsole::TestResult.new suites = Minitest::Runnable.runnables suites.each do |suite| suite.methods_matching(/^test/).map do |method| id = results.add_element(suite, method) end end results end |
Instance Method Details
#match_and_run(match_patterns, config) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/tconsole/minitest_handler.rb', line 14 def match_and_run(match_patterns, config) suites = Minitest::Runnable.runnables @reporter.ready suites.each do |suite| suite_id = @reporter.tc_results.elements[suite.to_s] suite_printed = false suite.methods_matching(/^test/).map do |method| if @interrupted return @reporter.tc_results end id = @reporter.tc_results.add_element(suite, method) unless match_patterns.nil? match = match_patterns.find do |pattern| pattern == suite.to_s || pattern == "#{suite.to_s}##{method.to_s}" || pattern == suite_id.to_s || pattern == id end end if !suite_printed && (match_patterns.nil? || match_patterns.empty? || !match.nil?) print(::Term::ANSIColor.cyan, suite, ::Term::ANSIColor.reset, ::Term::ANSIColor.magenta, " #{suite_id} \n") suite_printed = true end if match_patterns.nil? || match_patterns.empty? || !match.nil? @reporter.current_element_id = id # TODO мб понтово свой метод run в минитест захуярить, # который список suites принимать будет Minitest::Runnable.run_one_method(suite, method, @reporter) end end if suite_printed puts end end [@reporter.tc_results, @reporter] end |