updated to work with miniunit 1.1.0
[augment.git] / lib / backends / test_unit_backend.rb
blob4b9f43d81f5405d0889e855c3abcb45f3d709c7b
1 Object.flet(:at_exit => lambda {}) do
2   # keep miniunit's at_exit block from running
3   gem 'miniunit', ">= 1.1.0"
4   require 'test/unit'
5 end
7 module MiniTest
8   class Unit
9     # Puke failures/errors in a bucket
10     def puke(*args) 
11       TestUnitBackend.failure_bucket(*args)
12     end
13   end
14 end
17 # Backend for gathering test results. Instead of ntalbott's test/unit
18 # which ships with Ruby as of 1.8.6, this uses miniunit, a vastly
19 # simpler mostly-compatible replacement.
21 class TestUnitBackend < Backend
22   class << self
23     # Kicks off a miniunit run and captures the failures
24     def run(file)
25       @file = file
26       @layers = {}
28       load(find_test_for(file))
29       # this will call record_failure as needed
30       with_no_output { Test::Unit.autotest }
31       write_layers
32     end
34     def failure_bucket(klass, method, exception)
35       # FIXME: errors here could actually occur in impl rather than test file
36       color = Test::Assertion === exception ? 'red' : 'yellow'
37       line = exception.backtrace.grep(Regexp.new(@file))[0].match(/:(\d*):/)[1].to_i
39       (@layers[@file] ||= []) << Layer.new(line, color, exception.message, self, @file)
40     end
42     # This should allow us to augment a test by running its associated
43     # implementation
44     def find_test_for(file)
45       # TODO: return test for implementation if possible
46       file
47     end
48   end
49   
50   Augment::BACKENDS['test'] = self
51 end