Sha256: 923945b356b5af0234eb811fb93a52e0f7b35806df674f08ee594dedb741f8da

Contents?: true

Size: 1.97 KB

Versions: 9

Compression:

Stored size: 1.97 KB

Contents

module Teaspoon
  module Formatter
    module ReportModule
      RED = 31
      GREEN = 32
      YELLOW = 33
      CYAN = 36

      def log_error(result)
        log_line(result.message, RED)
        (result.trace || []).each do |trace|
          function = trace["function"].present? ? " -- #{trace['function']}" : ""
          log_line("  # #{filename(trace['file'])}:#{trace['line']}#{function}", CYAN)
        end
        log_line
      end

      def log_result(result)
        log_information
        log_stats(result)
        log_failed_examples
      end

      def log_coverage(message)
        log_line("\n#{message}")
      end

      def log_threshold_failure(message)
        log_line("\n#{message}\n", RED)
      end

      private

      def log_information
        log_pending if pendings.size > 0
        log_failures if failures.size > 0
      end

      def log_pending
        log_line("Pending:")
        pendings.each do |result|
          log_line("  #{result.description}", YELLOW)
          log_line("    # Not yet implemented\n", CYAN)
        end
      end

      def log_failures
        log_line("Failures:\n")
        failures.each_with_index do |failure, index|
          log_line("  #{index + 1}) #{failure.description}")
          log_line("     Failure/Error: #{failure.message}\n", RED)
        end
      end

      def log_stats(result)
        log_line("Finished in #{result.elapsed} seconds")
        stats = "#{pluralize('example', run_count)}, #{pluralize('failure', failures.size)}"
        stats << ", #{pendings.size} pending" if pendings.size > 0
        log_line(stats, stats_color)
      end

      def log_failed_examples
        return if failures.size == 0
        log_line
        log_line("Failed examples:\n")
        failures.each do |failure|
          log_line("teaspoon -s #{@suite_name} --filter=\"#{failure.link}\"", RED)
        end
      end

      def stats_color
        failures.size > 0 ? RED : pendings.size > 0 ? YELLOW : GREEN
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

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