Sha256: cd7c8254630b94e32546beb94dfd27313afda627616ee6329ddd89455b98104b

Contents?: true

Size: 1.63 KB

Versions: 7

Compression:

Stored size: 1.63 KB

Contents

module Micronaut
  module Formatters

    class DocumentationFormatter < BaseTextFormatter

      attr_reader :previous_nested_behaviours

      def initialize
        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)
        super
        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

7 entries across 7 versions & 1 rubygems

Version Path
spicycode-micronaut-0.1.4.3 lib/micronaut/formatters/documentation_formatter.rb
spicycode-micronaut-0.1.4.4 lib/micronaut/formatters/documentation_formatter.rb
spicycode-micronaut-0.1.5.2 lib/micronaut/formatters/documentation_formatter.rb
spicycode-micronaut-0.1.5 lib/micronaut/formatters/documentation_formatter.rb
spicycode-micronaut-0.1.6.1 lib/micronaut/formatters/documentation_formatter.rb
spicycode-micronaut-0.1.6.8 lib/micronaut/formatters/documentation_formatter.rb
spicycode-micronaut-0.1.6 lib/micronaut/formatters/documentation_formatter.rb