Sha256: 1657cb9a43456887ad8140954b7d7ea6b5a5127e414fda4ece6bdd68f6e4c18b

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 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::Logging)
          puts '', " #{NAME} -- #{description} [FAILED]".center(70, '-'), ''
          colors = Ramaze::Informer::COLORS

          until RamazeLogger.history.empty?
            tag, line = RamazeLogger.history.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::Logging)
  module Ramaze
    class SpecLogger
      include Ramaze::Logging
      include Enumerable

      attr_accessor :history

      def initialize
        @history = []
      end

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

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ramaze-0.3.9.1 lib/ramaze/spec/helper/pretty_output.rb
ramaze-0.3.9 lib/ramaze/spec/helper/pretty_output.rb