class SpecRunner def initialize(spec) self.spec = spec self.stopped = false self.bail = false self.bailed = false self.tag = '' end defm set_bail(bail) self.bail = bail end defm set_tag(tag) self.tag = tag end defm has_bailed() return self.bailed end defm start(reporter, stats) spec = self.spec did_fail = false context = self.call_hook('describe') reporter.on_context_start(context, stats) self.call_hook('before') for method in keys(spec) if self.stopped break end if self.can_run_test_for(method) timer = new SpecTimer() meta = new SpecMeta(context, method) reporter.on_spec_start(meta, stats) result = 0 try self.call_hook('before_each') timer.start() eval("spec.#{method}()") timer.stop() self.call_hook('after_each') meta.set_duration(timer.get_duration()) stats.inc_passes() reporter.on_spec_pass(meta, stats) catch /Unknown function.*expect/ did_fail = true stats.inc_failures() exception = 'DSLError: expect() not found, dsl.riml may not be included' reporter.on_spec_failure(meta, exception, stats) catch /Unknown function.*define_matcher/ did_fail = true stats.inc_failures() exception = 'DSLError: define_matcher() not found, dsl.riml may not be included' reporter.on_spec_failure(meta, exception, stats) catch /^AssertionError/ did_fail = true stats.inc_failures() reporter.on_spec_failure(meta, v:exception, stats) catch /.*/ did_fail = true stats.inc_errors() reporter.on_spec_error(meta, v:exception, stats) end reporter.on_spec_end(meta, stats) :redraw if did_fail && self.bail self.bailed = true break end end end self.call_hook('after') reporter.on_context_end(context, stats) end defm call_hook(hook) spec = self.spec if has_key(spec, hook) return eval("spec.#{hook}()"); else return "Undefined hook: #{hook}" end end defm stop() self.stopped = true end defm is_test_method(method) return method =~ '^it' end defm is_method_tagged(method) return method =~ "_#{self.tag}$" end defm can_run_test_for(method) if self.tag == '' return self.is_test_method(method) else return self.is_test_method(method) && self.is_method_tagged(method) end end end