Sha256: 2c7a2c097646dc585fe0c95e2cba3ba4b0c20cfada117bb37dc200bfc3024afe

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

module Bacon
  module PrettyOutput
    NAME = ''

    def handle_specification(name)
      NAME.replace name
			puts NAME
      yield
			puts
    end

    def handle_requirement(description)
	    print "- #{description}\n"
      error = yield

      unless error.empty?
        if defined?(Ramaze::Informing)
          puts '', " #{NAME} -- #{description} [FAILED]".center(70, '-'), ''
          colors = Ramaze::Informer::COLORS

          until RamazeLogger.log.empty?
            tag, line = RamazeLogger.log.shift
            out = "%6s | %s" % [tag.to_s, line]
            puts out.send(colors[tag])
          end
        end

        general_error
      end
    end

    def general_error
      puts "", ErrorLog
      ErrorLog.scan(/^\s*(.*?):(\d+): #{NAME} - (.*?)$/) do
        puts "#{ENV['EDITOR'] || 'vim'} #$1 +#$2 # #$3"
      end
      ErrorLog.replace ''
    end

    def handle_summary
	    puts
      puts "%d tests, %d assertions, %d failures, %d errors" %
        Counter.values_at(:specifications, :requirements, :failed, :errors)
    end
  end
end

if defined?(Ramaze::Informing)
  module Ramaze
    class SpecLogger
      include Ramaze::Informing
      include Enumerable

      attr_accessor :log

      def initialize
        @log = []
      end

      def each
        @log.each{|e| yield(e) }
      end

      def inform(tag, str)
        @log << [tag, str]
      end
    end
  end

  module Bacon::PrettyOutput
    RamazeLogger = Ramaze::SpecLogger.new
    Ramaze::Inform.loggers = [RamazeLogger]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ramaze-0.3.5 lib/ramaze/spec/helper/pretty_output.rb