Sha256: 47fa17642c0bffd5d0e30c3356cf8426256d9f9d35cffa0b649698a936f322e0

Contents?: true

Size: 868 Bytes

Versions: 9

Compression:

Stored size: 868 Bytes

Contents

require "teaspoon/formatter/dot"

module Teaspoon
  module Formatter
    class Pride < Dot
      PI_3 = Math::PI / 3

      def initialize(*args)
        @color_index = 0
        super
      end

      protected

      def log_spec(result)
        return log_pride if result.passing?
        super
      end

      private

      def log_pride
        return log_str(".") unless Teaspoon.configuration.color
        log_str("\e[38;5;#{next_color}m.\e[0m")
      end

      def colors
        @colors ||= (0...42).map do |i|
          i *= 1.0 / 6
          36 * calc_color(i) + 6 * calc_color(i + 2 * PI_3) + calc_color(i + 4 * PI_3) + 16
        end
      end

      def calc_color(val)
        (3 * Math.sin(val) + 3).to_i
      end

      def next_color
        c = colors[@color_index % colors.size]
        @color_index += 1
        c
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
teaspoon-1.1.5 lib/teaspoon/formatter/pride.rb
teaspoon-1.1.4 lib/teaspoon/formatter/pride.rb
teaspoon-1.1.3 lib/teaspoon/formatter/pride.rb
teaspoon-1.1.2 lib/teaspoon/formatter/pride.rb
teaspoon-1.1.1 lib/teaspoon/formatter/pride.rb
teaspoon-1.1.0 lib/teaspoon/formatter/pride.rb
teaspoon-1.0.2 lib/teaspoon/formatter/pride.rb
teaspoon-1.0.1 lib/teaspoon/formatter/pride.rb
teaspoon-1.0.0 lib/teaspoon/formatter/pride.rb