Module: TestConsole::Builder

Includes:
Config
Included in:
TestConsole
Defined in:
lib/test_console/builder.rb

Instance Method Summary collapse

Instance Method Details

#filter_tests(suite, filter) ⇒ Object

Suite generation functions

Functions to generate and refine suites of tests



11
12
13
14
15
16
# File 'lib/test_console/builder.rb', line 11

def filter_tests(suite, filter)
  STDOUT.puts color("Filtering with #{filter.inspect}", :yellow)
  new_suite = Test::Unit::TestSuite.new(suite.name)
  suite.tests.each{|t| new_suite.tests << t if t.name.match filter}
  new_suite
end

#make_suite_from_file(test_filename, filter = nil) ⇒ Object

Creates a test suite based on a path to a test file



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/test_console/builder.rb', line 19

def make_suite_from_file(test_filename, filter=nil)
  test_file = File.join(test_filename)
  raise "Can't find #{test_file}" and return unless File.exists?(test_file)

  klass = Utility.class_from_filename(test_file)

  Utility.const_remove(klass) if Utility.const_defined?(klass)
  load test_file

  if Utility.const_defined?(klass)
    return suite = Utility.const_get(klass).suite
  else
    raise "WARNING: #{test_filename} does not define #{klass.join('/')}"
  end
end

#make_suite_from_folder(path, filter = nil) ⇒ Object

Creates a test suite based on a path to a folder of tests



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/test_console/builder.rb', line 36

def make_suite_from_folder(path, filter=nil)
  suite = Test::Unit::TestSuite.new(path)

  Dir.glob(File.join("**", "*_test.rb")).each do |fname|
    if fname[0..dummy_folder.length] != "#{dummy_folder}/"
      klass = Utility.class_from_filename(fname)

      Utility.const_remove(klass) if Utility.const_defined?(klass)

      load fname

      if Utility.const_defined?(klass)
        Utility.const_get(klass).suite.tests.each {|t| suite.tests << t}
      else
        raise "WARNING: #{fname} does not define #{klass.join('/')}"
      end
    end
  end
  return suite
end