Sha256: 2e3be9f4864eb4e503b61472dc49aaf71b25246e4949b002049e0fef97721675

Contents?: true

Size: 1.39 KB

Versions: 9

Compression:

Stored size: 1.39 KB

Contents

require "teaspoon/formatter/base"
require "teaspoon/formatter/modules/report_module"

module Teaspoon
  module Formatter
    class Documentation < Base
      include ReportModule

      protected

      def initialize(*args)
        @level = 0
        super
      end

      def log_suite(result)
        log_indent_line(result.label, result.level)
        @level = result.level
      end

      def log_passing_spec(result)
        log_indent_spec(result.label, GREEN)
      end

      def log_pending_spec(result)
        log_indent_spec("#{result.label} (PENDING)", YELLOW)
      end

      def log_failing_spec(result)
        log_indent_spec("#{result.label} (FAILED - #{@failures.length})", RED)
      end

      def log_result(result)
        log_line
        super
      end

      private

      def log_indent_spec(str, color)
        log_indent_line(str, level = (@last_suite ? @level + 1 : 0), color)
        log_intent_stdout(level + 1)
      end

      def log_intent_stdout(level)
        return if @stdout.blank?
        log_indent_line("# #{@stdout.gsub(/\n$/, '').gsub("\n", "\n# ")}", level, CYAN)
      end

      def log_indent_line(str = "", level = nil, color = nil)
        log_line(indent(str, level || @level), color)
      end

      def indent(str = "", level = nil)
        indent = " " * (level * 2)
        str.gsub!("\n", "\n#{indent}")
        "#{indent}#{str}"
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
teaspoon-1.1.5 lib/teaspoon/formatter/documentation.rb
teaspoon-1.1.4 lib/teaspoon/formatter/documentation.rb
teaspoon-1.1.3 lib/teaspoon/formatter/documentation.rb
teaspoon-1.1.2 lib/teaspoon/formatter/documentation.rb
teaspoon-1.1.1 lib/teaspoon/formatter/documentation.rb
teaspoon-1.1.0 lib/teaspoon/formatter/documentation.rb
teaspoon-1.0.2 lib/teaspoon/formatter/documentation.rb
teaspoon-1.0.1 lib/teaspoon/formatter/documentation.rb
teaspoon-1.0.0 lib/teaspoon/formatter/documentation.rb