Sha256: 8c1645c00f591b6e0ef63203069171ef1fe52f982bbbe7d53f88d454c4963593

Contents?: true

Size: 1.93 KB

Versions: 8

Compression:

Stored size: 1.93 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

8 entries across 8 versions & 2 rubygems

Version Path
rspec-core-3.0.4 lib/rspec/core/formatters/documentation_formatter.rb
rspec-core-3.0.3 lib/rspec/core/formatters/documentation_formatter.rb
rspec-core-3.0.2 lib/rspec/core/formatters/documentation_formatter.rb
whos_dated_who-0.1.0 vendor/bundle/gems/rspec-core-3.0.1/lib/rspec/core/formatters/documentation_formatter.rb
whos_dated_who-0.0.1 vendor/bundle/gems/rspec-core-3.0.1/lib/rspec/core/formatters/documentation_formatter.rb
rspec-core-3.0.1 lib/rspec/core/formatters/documentation_formatter.rb
rspec-core-3.0.0 lib/rspec/core/formatters/documentation_formatter.rb
rspec-core-3.0.0.rc1 lib/rspec/core/formatters/documentation_formatter.rb