Class: AsProject::TestSuiteGenerator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start, suite_name, template_content) ⇒ TestSuiteGenerator

Returns a new instance of TestSuiteGenerator.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/test_suite_generator.rb', line 6

def initialize(start, suite_name, template_content)
  remove_test_suites(start)
  @created_files = []
  @test_suites = []
  return_to = Dir.pwd
  Dir.chdir(start)
  process_dir(Dir.pwd, suite_name)
  process_test_suites(@test_suites, template_content)
  finish
  Dir.chdir(return_to)
end

Instance Attribute Details

#created_filesObject

Returns the value of attribute created_files.



4
5
6
# File 'lib/test_suite_generator.rb', line 4

def created_files
  @created_files
end

#test_suitesObject

Returns the value of attribute test_suites.



4
5
6
# File 'lib/test_suite_generator.rb', line 4

def test_suites
  @test_suites
end

Instance Method Details

#build_base_name(base, file) ⇒ Object



60
61
62
63
64
65
# File 'lib/test_suite_generator.rb', line 60

def build_base_name(base, file)
  if(base == '')
    return file
  end
  return File.join(base, file)
end

#finishObject



18
19
20
21
22
# File 'lib/test_suite_generator.rb', line 18

def finish
  Logger.puts ''
  Logger.puts '>> TestSuites rebuilt from: '
  Logger.puts Dir.pwd
end

#process_dir(dir, suite_name, base = '') ⇒ Object



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
# File 'lib/test_suite_generator.rb', line 31

def process_dir(dir, suite_name, base='')
  found_test_case = false
  suite = TestSuite.new(dir, suite_name)
  suite.directory = base
  
  Dir.foreach(dir) do |file|
    if(file == '.' || file == '..')
      next
    end
    if(File.directory?(file) && !AsProject.ignore_file?(file))
      Dir.chdir(file)
      if(process_dir(Dir.pwd, suite_name, build_base_name(base, file)))
        suite.add_test_suite(build_base_name(base, file))
        found_test_case = true
      end
      Dir.chdir('../')
    end
    if(File.fnmatch('*Test.as', file))
      suite.add_test_case(build_base_name(base, file))
      found_test_case = true
    end
  end
  
  if(found_test_case)
    @test_suites << suite
  end
  return found_test_case
end

#process_test_suites(suites, template_content) ⇒ Object



67
68
69
70
71
72
# File 'lib/test_suite_generator.rb', line 67

def process_test_suites(suites, template_content)
  suites.each do |suite|
    suite.serialize(template_content)
    @created_files << suite.file_location
  end
end

#remove_test_suites(dir) ⇒ Object



24
25
26
27
28
29
# File 'lib/test_suite_generator.rb', line 24

def remove_test_suites(dir)
  files = Dir["#{dir}/**/**AllTests.as"]
  files.each do |file|
    File.delete file
  end
end