Sha256: 15fb3a3d5996263c63fd40449c3c91907273ad83234df2675251e9fd15e22b9f

Contents?: true

Size: 1.88 KB

Versions: 5

Compression:

Stored size: 1.88 KB

Contents

module Specjour::Rspec
  class DistributedFormatter < Spec::Runner::Formatter::BaseTextFormatter
    require 'specjour/rspec/marshalable_rspec_failure'

    attr_reader :failing_messages, :passing_messages, :pending_messages, :output
    attr_reader :duration, :example_count, :failure_count, :pending_count, :pending_examples, :failing_examples

    def initialize(options, output)
      @options = options
      @output = output
      @failing_messages = []
      @passing_messages = []
      @pending_messages = []
      @pending_examples = []
      @failing_examples = []
    end

    def example_failed(example, counter, failure)
      failing_messages << colorize_failure('F', failure)
      print_and_flush(failing_messages)
    end

    def example_passed(example)
      passing_messages << green('.')
      print_and_flush(passing_messages)
    end

    def example_pending(example, message, deprecated_pending_location=nil)
      super
      pending_messages << yellow('*')
      print_and_flush(pending_messages)
    end

    def dump_summary(duration, example_count, failure_count, pending_count)
      @duration = duration
      @example_count = example_count
      @failure_count = failure_count
      @pending_count = pending_count
      output.send_message(:rspec_summary=, to_hash)
    end

    def dump_pending
      #noop
    end

    def dump_failure(counter, failure)
      failing_examples << failure
    end

    def start_dump
      print_and_flush failing_messages
      print_and_flush passing_messages
      print_and_flush pending_messages
    end

    def to_hash
      h = {}
      [:duration, :example_count, :failure_count, :pending_count, :pending_examples, :failing_examples].each do |key|
        h[key] = send(key)
      end
      h
    end

    protected

    def print_and_flush(messages)
      output.print messages.to_s
      output.flush
      messages.replace []
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
specjour-0.3.0.rc5 lib/specjour/rspec/distributed_formatter.rb
specjour-0.3.0.rc4 lib/specjour/rspec/distributed_formatter.rb
specjour-0.3.0.rc3 lib/specjour/rspec/distributed_formatter.rb
specjour-0.3.0.rc2 lib/specjour/rspec/distributed_formatter.rb
specjour-0.3.0.rc1 lib/specjour/rspec/distributed_formatter.rb