Class: DeepTest::Test::Collector::RailsOrderedObjectSpace

Inherits:
Test::Unit::Collector::ObjectSpace
  • Object
show all
Defined in:
lib/deep_test/test/collector/rails_ordered_object_space.rb

Overview

This allows us to run tests in a similar order to how rails normal runs them (i.e. units, functionals, integration) without having to mintain the test file loading order and passing it down the line somehow.

Instance Method Summary collapse

Instance Method Details

#filter_and_sort_suites(suites, klass) ⇒ Object



46
47
48
# File 'lib/deep_test/test/collector/rails_ordered_object_space.rb', line 46

def filter_and_sort_suites(suites, klass)
  suites.select {|s| s.name.constantize < klass}.sort_by {|s| suite_to_filename(s)}
end

#sort(suites) ⇒ Object



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
# File 'lib/deep_test/test/collector/rails_ordered_object_space.rb', line 18

def sort(suites)
  done = int = filter_and_sort_suites(suites, ActionController::IntegrationTest)
  done += func = filter_and_sort_suites(suites - done, ActionController::TestCase)
  done += others = filter_and_sort_suites(suites - done, ::Test::Unit::TestCase)
  
  ordered = others + func + int
  if ordered.size == suites.size
    ordered
  else
    oddballs = suites - ordered
    
    warn <<-STR

WARNING:
    Deep Test isn\'t sure it has preserved the standard test running order.
    Tests that aren\'t of the standard rails unit, functional, or integration
    classes will be run after those that are.

The #{oddballs.uniq.size} oddballs are of classes: #{oddballs.map(&:name).uniq.inspect}

oddballs:
#{oddballs.inspect}

STR
    ordered + oddballs
  end
end

#suite_to_filename(s) ⇒ Object



50
51
52
# File 'lib/deep_test/test/collector/rails_ordered_object_space.rb', line 50

def suite_to_filename(s)
  s.name.underscore + ".rb"
end