Sha256: 42f96c283deeeff8319977d839c37ab4f38294321f07fe482b3dc4c8aaaad1eb

Contents?: true

Size: 1.92 KB

Versions: 34

Compression:

Stored size: 1.92 KB

Contents

RSpec::Support.require_rspec_core "formatters/base_text_formatter"

module RSpec
  module Core
    module Formatters
      # @private
      class DocumentationFormatter < BaseTextFormatter
        Formatters.register self, :example_group_started, :example_group_finished,
                            :example_passed, :example_pending, :example_failed

        def initialize(output)
          super
          @group_level = 0
        end

        def example_group_started(notification)
          output.puts if @group_level == 0
          output.puts "#{current_indentation}#{notification.group.description.strip}"

          @group_level += 1
        end

        def example_group_finished(_notification)
          @group_level -= 1
        end

        def example_passed(passed)
          output.puts passed_output(passed.example)
        end

        def example_pending(pending)
          output.puts pending_output(pending.example, pending.example.execution_result.pending_message)
        end

        def example_failed(failure)
          output.puts failure_output(failure.example, failure.example.execution_result.exception)
        end

      private

        def passed_output(example)
          ConsoleCodes.wrap("#{current_indentation}#{example.description.strip}", :success)
        end

        def pending_output(example, message)
          ConsoleCodes.wrap("#{current_indentation}#{example.description.strip} (PENDING: #{message})", :pending)
        end

        def failure_output(example, _exception)
          ConsoleCodes.wrap("#{current_indentation}#{example.description.strip} (FAILED - #{next_failure_index})", :failure)
        end

        def next_failure_index
          @next_failure_index ||= 0
          @next_failure_index += 1
        end

        def current_indentation
          '  ' * @group_level
        end

        def example_group_chain
          example_group.parent_groups.reverse
        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/documentation_formatter.rb
opal-rspec-0.8.0.alpha3 rspec-core/upstream/lib/rspec/core/formatters/documentation_formatter.rb
opal-rspec-0.8.0.alpha2 rspec-core/upstream/lib/rspec/core/formatters/documentation_formatter.rb
opal-rspec-0.8.0.alpha1 rspec-core/upstream/lib/rspec/core/formatters/documentation_formatter.rb
opal-rspec-0.7.1 rspec-core/upstream/lib/rspec/core/formatters/documentation_formatter.rb
opal-rspec-0.7.0 rspec-core/upstream/lib/rspec/core/formatters/documentation_formatter.rb
opal-rspec-0.6.2 rspec-core/lib/rspec/core/formatters/documentation_formatter.rb
opal-rspec-0.7.0.rc.2 rspec-core/upstream/lib/rspec/core/formatters/documentation_formatter.rb
opal-rspec-0.6.1 rspec-core/lib/rspec/core/formatters/documentation_formatter.rb
opal-rspec-0.6.0 rspec-core/lib/rspec/core/formatters/documentation_formatter.rb
opal-rspec-0.6.0.beta1 rspec-core/lib/rspec/core/formatters/documentation_formatter.rb
opal-connect-rspec-0.5.0 rspec-core/lib/rspec/core/formatters/documentation_formatter.rb
able-neo4j-1.0.0 vendor/bundle/jruby/1.9/gems/rspec-core-3.1.7/lib/rspec/core/formatters/documentation_formatter.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/rspec-core-3.1.1/lib/rspec/core/formatters/documentation_formatter.rb
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/rspec-core-3.1.1/lib/rspec/core/formatters/documentation_formatter.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/rspec-core-3.1.1/lib/rspec/core/formatters/documentation_formatter.rb
opal-rspec-0.5.0 rspec-core/lib/rspec/core/formatters/documentation_formatter.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/rspec-core-3.1.7/lib/rspec/core/formatters/documentation_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/documentation_formatter.rb
logstash-codec-json-2.0.3 vendor/gems/rspec-core-3.1.7/lib/rspec/core/formatters/documentation_formatter.rb