Sha256: 2326e4663979accef56843cc0d4ac748b9d38f876daaac2073056c0ed9f873cb

Contents?: true

Size: 1.91 KB

Versions: 3

Compression:

Stored size: 1.91 KB

Contents

require 'rspec/core/formatters/progress_formatter'

module Fivemat
  class RSpec < ::RSpec::Core::Formatters::ProgressFormatter
    include ElapsedTime

    def initialize(*)
      super
      @group_level = 0
      @index_offset = 0
      @cumulative_failed_examples = []
    end

    def example_group_started(group)
      if @group_level.zero?
        output.print "#{group.description} "
        @failure_output = []
        @start_time = Time.now
      end
      @group_level += 1
    end

    def example_group_finished(group)
      @group_level -= 1
      if @group_level.zero?
        print_elapsed_time output, @start_time
        output.puts

        failed_examples.each_with_index do |example, index|
          if pending_fixed?(example)
            dump_pending_fixed(example, @index_offset + index)
          else
            dump_failure(example, @index_offset + index)
          end
          dump_backtrace(example)
        end
        @index_offset += failed_examples.size
        @cumulative_failed_examples += failed_examples
        failed_examples.clear
      end
    end

    def pending_fixed?(example)
      if example.execution_result[:exception].respond_to?(:pending_fixed?)
        example.execution_result[:exception].pending_fixed?
      else
        ::RSpec::Core::PendingExampleFixedError === example.execution_result[:exception]
      end
    end

    def dump_pending_fixed(example, index)
      output.puts "#{short_padding}#{index.next}) #{example.full_description} FIXED"
      output.puts blue("#{long_padding}Expected pending '#{example.metadata[:execution_result][:pending_message]}' to fail. No Error was raised.")
    end

    def dump_summary(*)
      @failed_examples = @cumulative_failed_examples
      super
    end

    def start_dump
      # Skip the call to output.puts in the messiest way possible.
      self.class.superclass.superclass.instance_method(:start_dump).bind(self).call
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fivemat-1.3.1 lib/fivemat/rspec.rb
fivemat-1.3.0 lib/fivemat/rspec.rb
fivemat-1.2.1 lib/fivemat/rspec.rb