123456789_123456789_123456789_123456789_123456789_

Class: Test::Unit::TestSuiteCreator

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: lib/test/unit/test-suite-creator.rb

Class Method Summary

Instance Method Summary

Constructor Details

.new(test_case) ⇒ TestSuiteCreator

[ GitHub ]

  
# File 'lib/test/unit/test-suite-creator.rb', line 18

def initialize(test_case)
  @test_case = test_case
end

Class Method Details

.test_method?(test_case, method_name) ⇒ Boolean

[ GitHub ]

  
# File 'lib/test/unit/test-suite-creator.rb', line 12

def test_method?(test_case, method_name)
  /\Atest./ =~ method_name.to_s or
    test_case.find_attribute(method_name, :test)
end

Instance Method Details

#append_test(suite, test_name) {|test| ... } (private)

Yields:

  • (test)
[ GitHub ]

  
# File 'lib/test/unit/test-suite-creator.rb', line 45

def append_test(suite, test_name)
  test = @test_case.new(test_name)
  yield(test) if block_given?
  suite << test if test.valid?
end

#collect_test_names (private)

[ GitHub ]

  
# File 'lib/test/unit/test-suite-creator.rb', line 51

def collect_test_names
  methods = @test_case.public_instance_methods(true)
  super_test_case = @test_case.superclass
  methods -= super_test_case.public_instance_methods(true)
  methods |= @test_case.public_instance_methods(false)
  method_names = methods.collect(&:to_s)
  test_names = method_names.find_all do |method_name|
    self.class.test_method?(@test_case, method_name)
  end
  __send__("sort_test_names_in_#{@test_case.test_order}_order", test_names)
end

#create

[ GitHub ]

  
# File 'lib/test/unit/test-suite-creator.rb', line 22

def create
  suite = TestSuite.new(@test_case.name, @test_case)
  collect_test_names.each do |test_name|
    data_sets = @test_case.find_attribute(test_name, :data,
                                          :recursive => false)
    if data_sets
      data_sets.each do |data_set|
        data_set = data_set.call if data_set.respond_to?(:call)
        data_set.each do |label, data|
          append_test(suite, test_name) do |test|
            test.assign_test_data(label, data)
          end
        end
      end
    else
      append_test(suite, test_name)
    end
  end
  append_test(suite, "default_test") if suite.empty?
  suite
end

#sort_test_names_in_alphabetic_order(test_names) (private)

[ GitHub ]

  
# File 'lib/test/unit/test-suite-creator.rb', line 63

def sort_test_names_in_alphabetic_order(test_names)
  test_names.sort
end

#sort_test_names_in_defined_order(test_names) (private)

[ GitHub ]

  
# File 'lib/test/unit/test-suite-creator.rb', line 71

def sort_test_names_in_defined_order(test_names)
  added_method_names = @test_case.added_method_names
  test_names.sort do |test1, test2|
    test1_defined_order = added_method_names.index(test1)
    test2_defined_order = added_method_names.index(test2)
    if test1_defined_order and test2_defined_order
      test1_defined_order <=> test2_defined_order
    elsif test1_defined_order
      1
    elsif test2_defined_order
      -1
    else
      test1 <=> test2
    end
  end
end

#sort_test_names_in_random_order(test_names) (private)

[ GitHub ]

  
# File 'lib/test/unit/test-suite-creator.rb', line 67

def sort_test_names_in_random_order(test_names)
  test_names.sort_by {rand(test_names.size)}
end