Class: Tack::Adapters::TestUnitAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/tack/adapters/test_unit_adapter.rb

Instance Method Summary collapse

Instance Method Details

#run(path, description) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/tack/adapters/test_unit_adapter.rb', line 23

def run(path, description)
  results = { :passed => [],
    :failed => [],
    :pending => []}
  require(path)
  # Note that this won't work if there are multiple classes in a file
  klass = test_classes_for(path).first 
  test = klass.new(description)
  result = Test::Unit::TestResult.new

  result.add_listener(Test::Unit::TestResult::FAULT) do |failure|
    results[:failed] << build_result(description, failure)
  end
  
  test.run(result) do |started,name|
    # We do nothing here
    # but this method requires a block
  end
  if result.passed?
    results[:passed] << build_result(description)
  end
  results
end

#tests_for(file, pattern) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/tack/adapters/test_unit_adapter.rb', line 15

def tests_for(file, pattern)
  require file
  classes = test_classes_for(file)
  classes.inject([]) do |tests, klass|
    tests += test_methods(klass).map {|method_name| [file, method_name.to_s]}.select {|file, method_name| method_name.match(pattern)}
  end
end