Sha256: bb7bd9985ff8c444114df5aef56bc294925acf7c8c5dafec0341b98269cb7ca5
Contents?: true
Size: 1.44 KB
Versions: 5
Compression:
Stored size: 1.44 KB
Contents
require "json" require "teaspoon/result" module Teaspoon class Runner attr_accessor :formatters attr_reader :failure_count def initialize(suite_name = :default) @suite_name = suite_name @formatters = Teaspoon.configuration.formatters.map{ |f| resolve_formatter(f).new(suite_name) } @failure_count = 0 end def suppress_logs? return @suppress_logs unless @suppress_logs.nil? @suppress_logs = Teaspoon.configuration.suppress_log return true if @suppress_logs for formatter in @formatters return @suppress_logs = true if formatter.suppress_logs? end @suppress_logs = false end def process(line) return if output_from(line) log line unless suppress_logs? end private def resolve_formatter(formatter) Teaspoon::Formatters.const_get("#{formatter.to_s.camelize}Formatter") end def output_from(line) json = JSON.parse(line) return false unless json && json["_teaspoon"] && json["type"] result = Teaspoon::Result.build_from_json(json) notify_formatters result @failure_count += 1 if result.failing? return true rescue JSON::ParserError false end def notify_formatters(result) @formatters.each do |formatter| event = result.type formatter.send(event, result) if formatter.respond_to?(event) end end def log(msg) STDOUT.print msg end end end
Version data entries
5 entries across 5 versions & 1 rubygems