<commit_before>require 'cucumber/formatters/ansicolor'

module Cucumber
  module Formatters
    class PrettyFormatter
      include ANSIColor

      INDENT = "\n      "
    
      def initialize(io)
        @io = (io == STDOUT) ? Kernel : io
        @passed = []
        @failed = []
        @pending = []
        @skipped = []
      end
    
      def header_executing(header)
        @io.puts if @feature_newline
        @feature_newline = true
        @io.puts passed(header)
        @io.puts
      end
  
      def scenario_executing(scenario)
        @scenario_failed = false
        if scenario.row?
          @io.print "    |"
        else
          @io.puts passed("  #{Cucumber.language['scenario']}: #{scenario.name}")
        end
      end

      def scenario_executed(scenario)
        @io.puts
        if !scenario.row? && scenario.table_header
          @io.print "    |"
          scenario.table_header.each { |h| @io.print h ; @io.print "|" }
          @io.puts
        elsif scenario.row? && @scenario_failed
          @io.puts
          step_failed(@failed.last) 
        end
      end
      
      def step_executed(step, regexp, args)
        if step.row?
          row_step_executed(step, regexp, args)
        else
          regular_step_executed(step, regexp, args)
        end
      end
      
      def regular_step_executed(step, regexp, args)
        case(step.error)
        when Pending
          @pending << step
          @io.puts pending("    #{step.keyword} #{step.name}")
        when NilClass
          @passed << step
          @io.puts passed("    #{step.keyword} #{step.format(regexp){|param| passed_param(param) << passed}}") 
        else
          @failed << step
          @scenario_failed = true
          @io.puts failed("    #{step.keyword} #{step.format(regexp){|param| failed_param(param) << failed}}") 
          step_failed(step)
        end
      end
      
      def row_step_executed(step, regexp, args)
        case(step.error)
        when Pending
          @pending << step
          args.each{|arg| @io.print pending(arg) ; @io.print "|"}
        when NilClass
          @passed << step
          args.each{|arg| @io.print passed(arg) ; @io.print "|"}
        else
          @failed << step
          @scenario_failed = true
          args.each{|arg| @io.print failed(arg) ; @io.print "|"}
        end
      end

      def step_skipped(step, regexp, args)
        @skipped << step
        if step.row?
          args.each{|arg| @io.print skipped(arg) ; @io.print "|"}
        else
          @io.puts skipped("    #{step.keyword} #{step.format(regexp){|param| skipped_param(param) << skipped}}") 
        end
        step_failed(step) if step.error
      end

      def step_failed(step)
        @io.puts failed("      #{step.error.message.split("\n").join(INDENT)} (#{step.error.class})")
        @io.puts failed("      #{step.error.backtrace.join(INDENT)}")
      end

      def dump
        @io.puts
        @io.puts passed("#{@passed.length} steps passed") unless @passed.empty?
        @io.puts failed("#{@failed.length} steps failed") unless @failed.empty?
        @io.puts skipped("#{@skipped.length} steps skipped") unless @skipped.empty?
        @io.puts pending("#{@pending.length} steps pending") unless @pending.empty?
        @io.print reset
        print_snippets
      end
      
      def print_snippets
        unless @pending.empty?
          @io.puts "\nYou can use these snippets to implement pending steps:\n\n"
          
          prev_keyword = nil<commit_msg>PrettyFormatter excludes Rails and Cucumber plugin from backtrace.<commit_after>require 'cucumber/formatters/ansicolor'

module Cucumber
  module Formatters
    class PrettyFormatter
      include ANSIColor

      INDENT = "\n      "
    
      def initialize(io)
        @io = (io == STDOUT) ? Kernel : io
        @passed = []
        @failed = []
        @pending = []
        @skipped = []
      end
    
      def header_executing(header)
        @io.puts if @feature_newline
        @feature_newline = true
        @io.puts passed(header)
        @io.puts
      end
  
      def scenario_executing(scenario)
        @scenario_failed = false
        if scenario.row?
          @io.print "    |"
        else
          @io.puts passed("  #{Cucumber.language['scenario']}: #{scenario.name}")
        end
      end

      def scenario_executed(scenario)
        @io.puts
        if !scenario.row? && scenario.table_header
          @io.print "    |"
          scenario.table_header.each { |h| @io.print h ; @io.print "|" }
          @io.puts
        elsif scenario.row? && @scenario_failed
          @io.puts
          step_failed(@failed.last) 
        end
      end
      
      def step_executed(step, regexp, args)
        if step.row?
          row_step_executed(step, regexp, args)
        else
          regular_step_executed(step, regexp, args)
        end
      end
      
      def regular_step_executed(step, regexp, args)
        case(step.error)
        when Pending
          @pending << step
          @io.puts pending("    #{step.keyword} #{step.name}")
        when NilClass
          @passed << step
          @io.puts passed("    #{step.keyword} #{step.format(regexp){|param| passed_param(param) << passed}}") 
        else
          @failed << step
          @scenario_failed = true
          @io.puts failed("    #{step.keyword} #{step.format(regexp){|param| failed_param(param) << failed}}") 
          step_failed(step)
        end
      end
      
      def row_step_executed(step, regexp, args)
        case(step.error)
        when Pending
          @pending << step
          args.each{|arg| @io.print pending(arg) ; @io.print "|"}
        when NilClass
          @passed << step
          args.each{|arg| @io.print passed(arg) ; @io.print "|"}
        else
          @failed << step
          @scenario_failed = true
          args.each{|arg| @io.print failed(arg) ; @io.print "|"}
        end
      end

      def step_skipped(step, regexp, args)
        @skipped << step
        if step.row?
          args.each{|arg| @io.print skipped(arg) ; @io.print "|"}
        else
          @io.puts skipped("    #{step.keyword} #{step.format(regexp){|param| skipped_param(param) << skipped}}") 
        end
        step_failed(step) if step.error
      end

      def step_failed(step)
        clean_backtrace = step.error.backtrace.map {|b| b.split("\n") }.flatten.reject do |line|
          line =~ /vendor\/rails/ or line =~ /vendor\/plugins\/cucumber/
        end.map { |line| line.strip }
        @io.puts failed("      #{step.error.message.split("\n").join(INDENT)} (#{step.error.class})")
        @io.puts failed("      #{clean_backtrace.join(INDENT)}")
      end

      def dump
        @io.puts
        @io.puts passed("#{@passed.length} steps passed") unless @passed.empty?
        @io.puts failed("#{@failed.length} steps failed") unless @failed.empty?
        @io.puts skipped("#{@skipped.length} steps skipped") unless @skipped.empty?
        @io.puts pending("#{@pending.length} steps pending") unless @pending.empty?
        @io.print reset
        print_snippets
      end
      
      def print_snippets
        unless @pending.empty?
          @io.puts "\nYou can use these snippets to implement pending steps:\n\n"
          
          prev_keyword = nil
{'fraction_non_alphanumeric': 0.12694300518134716, 'fraction_numerical': 0.0, 'mean_word_length': 1.8674745895230649, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5926066', 'n_tokens_mistral': 2323, 'n_tokens_neox': 2278, 'n_words': 489}