Sha256: 963848906050da9718d4b23416bcfab81ee16cff7095ed978e47805d12cfc3b5

Contents?: true

Size: 1.64 KB

Versions: 10

Compression:

Stored size: 1.64 KB

Contents

module Micronaut
  module Formatters

    class DocumentationFormatter < BaseTextFormatter

      attr_reader :previous_nested_behaviours

      def initialize(options, output_to)
        super
        @previous_nested_behaviours = []
      end

      def add_behaviour(behaviour)
        super

        described_behaviour_chain.each_with_index do |nested_behaviour, i|
          unless nested_behaviour == previous_nested_behaviours[i]
            desc_or_name = (i == 0) ? nested_behaviour.name : nested_behaviour.description
            output.puts "#{'  ' * i}#{desc_or_name}"
          end
        end
        
        @previous_nested_behaviours = described_behaviour_chain
      end

      def example_failed(example, exception)
        super
        expectation_not_met = exception.is_a?(Micronaut::Expectations::ExpectationNotMetError)
        
        message = if expectation_not_met
          "#{current_indentation}#{example.description} (FAILED)"
        else
          "#{current_indentation}#{example.description} (ERROR)"
        end

        @output.puts(expectation_not_met ? red(message) : magenta(message))
        @output.flush
      end

      def example_passed(example)
        output.puts green("#{current_indentation}#{example.description}")
        output.flush
      end

      def example_pending(example, message)
        super
        output.puts yellow("#{current_indentation}#{example.description} (PENDING: #{message})")
        output.flush
      end

      def current_indentation
        '  ' * previous_nested_behaviours.length
      end

      def described_behaviour_chain
        behaviour.ancestors
      end

    end
    
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
rsanheim-micronaut-0.1.3.2 lib/micronaut/formatters/documentation_formatter.rb
rsanheim-micronaut-0.1.4.1 lib/micronaut/formatters/documentation_formatter.rb
spicycode-micronaut-0.0.9 lib/micronaut/formatters/documentation_formatter.rb
spicycode-micronaut-0.1.0 lib/micronaut/formatters/documentation_formatter.rb
spicycode-micronaut-0.1.1 lib/micronaut/formatters/documentation_formatter.rb
spicycode-micronaut-0.1.2 lib/micronaut/formatters/documentation_formatter.rb
spicycode-micronaut-0.1.3 lib/micronaut/formatters/documentation_formatter.rb
spicycode-micronaut-0.1.4.1 lib/micronaut/formatters/documentation_formatter.rb
spicycode-micronaut-0.1.4.2 lib/micronaut/formatters/documentation_formatter.rb
spicycode-micronaut-0.1.4 lib/micronaut/formatters/documentation_formatter.rb