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
# File 'lib/test/unit/test-suite-creator.rb', line 20
def initialize(test_case) @test_case = test_case end
Class Method Details
.test_method?(test_case, method_name) ⇒ Boolean
# File 'lib/test/unit/test-suite-creator.rb', line 14
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)
# File 'lib/test/unit/test-suite-creator.rb', line 59
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 65
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 24
def create suite = TestSuite.new(@test_case.name, @test_case) collect_test_names.each do |test_name| data_sets = extract_data_sets(test_name) if data_sets data_sets.each do |label, data| append_test(suite, test_name) do |test| test.assign_test_data(label, data) end end else append_test(suite, test_name) end end append_test(suite, "default_test") if suite.empty? suite end
#extract_data_sets(test_name) (private)
[ GitHub ]# File 'lib/test/unit/test-suite-creator.rb', line 43
def extract_data_sets(test_name) data_sets = @test_case.find_attribute(test_name, :data, :recursive => false) data_method_name = "data_#{test_name}" test = @test_case.new(test_name) if test.respond_to?(data_method_name) data_method = test.method(data_method_name) if data_method.arity <= 0 data_sets ||= DataSets.new data_sets << data_method end end data_sets end
#sort_test_names_in_alphabetic_order(test_names) (private)
[ GitHub ]# File 'lib/test/unit/test-suite-creator.rb', line 77
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 85
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 81
def sort_test_names_in_random_order(test_names) test_names.sort_by {rand(test_names.size)} end