Sha256: 25dc2609a81a03cc1028158bc3f3882a2d4387a59f3f44c8fc16e512d69a6acb

Contents?: true

Size: 1.99 KB

Versions: 34

Compression:

Stored size: 1.99 KB

Contents

RSpec::Support.require_rspec_core "formatters/helpers"
require 'stringio'

module RSpec
  module Core
    module Formatters
      # RSpec's built-in formatters are all subclasses of RSpec::Core::Formatters::BaseTextFormatter.
      #
      # @see RSpec::Core::Formatters::BaseTextFormatter
      # @see RSpec::Core::Reporter
      # @see RSpec::Core::Formatters::Protocol
      class BaseFormatter
        # all formatters inheriting from this formatter will receive these notifications
        Formatters.register self, :start, :example_group_started, :close
        attr_accessor :example_group
        attr_reader :output

        # @api public
        # @param output [IO] the formatter output
        # @see RSpec::Core::Formatters::Protocol#initialize
        def initialize(output)
          @output = output || StringIO.new
          @example_group = nil
        end

        # @api public
        #
        # @param notification [StartNotification]
        # @see RSpec::Core::Formatters::Protocol#start
        def start(notification)
          start_sync_output
          @example_count = notification.count
        end

        # @api public
        #
        # @param notification [GroupNotification] containing example_group subclass of `RSpec::Core::ExampleGroup`
        # @see RSpec::Core::Formatters::Protocol#example_group_started
        def example_group_started(notification)
          @example_group = notification.group
        end

        # @api public
        #
        # @param notification [NullNotification]
        # @see RSpec::Core::Formatters::Protocol#close
        def close(_notification)
          restore_sync_output
        end

      private

        def start_sync_output
          @old_sync, output.sync = output.sync, true if output_supports_sync
        end

        def restore_sync_output
          output.sync = @old_sync if output_supports_sync && !output.closed?
        end

        def output_supports_sync
          output.respond_to?(:sync=)
        end
      end
    end
  end
end

Version data entries

34 entries across 31 versions & 8 rubygems

Version Path
opal-rspec-0.8.0 rspec-core/upstream/lib/rspec/core/formatters/base_formatter.rb
opal-rspec-0.8.0.alpha3 rspec-core/upstream/lib/rspec/core/formatters/base_formatter.rb
opal-rspec-0.8.0.alpha2 rspec-core/upstream/lib/rspec/core/formatters/base_formatter.rb
opal-rspec-0.8.0.alpha1 rspec-core/upstream/lib/rspec/core/formatters/base_formatter.rb
opal-rspec-0.7.1 rspec-core/upstream/lib/rspec/core/formatters/base_formatter.rb
opal-rspec-0.7.0 rspec-core/upstream/lib/rspec/core/formatters/base_formatter.rb
opal-rspec-0.6.2 rspec-core/lib/rspec/core/formatters/base_formatter.rb
opal-rspec-0.7.0.rc.2 rspec-core/upstream/lib/rspec/core/formatters/base_formatter.rb
opal-rspec-0.6.1 rspec-core/lib/rspec/core/formatters/base_formatter.rb
opal-rspec-0.6.0 rspec-core/lib/rspec/core/formatters/base_formatter.rb
opal-rspec-0.6.0.beta1 rspec-core/lib/rspec/core/formatters/base_formatter.rb
opal-connect-rspec-0.5.0 rspec-core/lib/rspec/core/formatters/base_formatter.rb
able-neo4j-1.0.0 vendor/bundle/jruby/1.9/gems/rspec-core-3.1.7/lib/rspec/core/formatters/base_formatter.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/rspec-core-3.1.1/lib/rspec/core/formatters/base_formatter.rb
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/rspec-core-3.1.1/lib/rspec/core/formatters/base_formatter.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/rspec-core-3.1.1/lib/rspec/core/formatters/base_formatter.rb
opal-rspec-0.5.0 rspec-core/lib/rspec/core/formatters/base_formatter.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/rspec-core-3.1.7/lib/rspec/core/formatters/base_formatter.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/logstash-codec-json-2.0.3/vendor/gems/rspec-core-3.1.7/lib/rspec/core/formatters/base_formatter.rb
logstash-codec-json-2.0.3 vendor/gems/rspec-core-3.1.7/lib/rspec/core/formatters/base_formatter.rb