Sha256: eaf6b536b75c8c9d07ddf4eb527657446c8b17b71ac728e9ef8c69ce9bd011e9

Contents?: true

Size: 1.46 KB

Versions: 4

Compression:

Stored size: 1.46 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

4 entries across 4 versions & 1 rubygems

Version Path
teaspoon-1.4.0 lib/teaspoon/formatter/documentation.rb
teaspoon-1.2.2 lib/teaspoon/formatter/documentation.rb
teaspoon-1.2.1 lib/teaspoon/formatter/documentation.rb
teaspoon-1.2.0 lib/teaspoon/formatter/documentation.rb