Sha256: 10ff63a718e1a218f391a15f5af5d0539f7ea2cc650add7cb7667d05f71582af

Contents?: true

Size: 1.93 KB

Versions: 7

Compression:

Stored size: 1.93 KB

Contents

# -*- coding: utf-8 -*-

require 'turnip_formatter/printer'
require 'ostruct'

module TurnipFormatter
  module Printer
    class TabTagStatistics
      class << self
        include TurnipFormatter::Printer

        def print_out(scenarios)
          tags = group_by_tag(scenarios)

          results = tags.map do |name, tag_scenarios|
            tag_analysis(name, tag_scenarios)
          end

          render_template(:tab_tag_statistics, { analysis_results: results })
        end

        private

        def tag_analysis(name, scenarios)
          status_group = scenarios.group_by { |s| s[:scenario].status }
          status_group.default = []

          info = OpenStruct.new(
            name: name,
            scenario_count: scenarios.size,
            passed_count: status_group["passed"].size,
            failed_count: status_group["failed"].size,
            pending_count: status_group["pending"].size,
            status: 'failed'
          )

          if info.failed_count.zero?
            info.status = info.pending_count.zero? ? 'passed' : 'pending'
          end

          info
        end

        #
        # Image...
        #
        # [
        #   { tags: [:a, :b], val: 3 },
        #   { tags: [:a], val: 4 },
        #   { tags: [:b], val: 5 },
        # ]
        # # => [
        #        [:a, [3, 4]],
        #        [:b, [3, 5]],
        #      ]
        #
        #
        def group_by_tag(scenarios)
          scenarios.map do |scenario|
            begin
              scenario.validation
              if scenario.tags.empty?
                { name: 'turnip', scenario: scenario }
              else
                scenario.tags.map do |tag|
                  { name: '@' + tag, scenario: scenario }
                end
              end
            rescue
              { name: 'runtime error', scenario: scenario }
            end
          end.flatten.group_by { |s| s[:name] }.sort
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
turnip_formatter-0.2.11 lib/turnip_formatter/printer/tab_tag_statistics.rb
turnip_formatter-0.2.10 lib/turnip_formatter/printer/tab_tag_statistics.rb
turnip_formatter-0.2.9 lib/turnip_formatter/printer/tab_tag_statistics.rb
turnip_formatter-0.2.8 lib/turnip_formatter/printer/tab_tag_statistics.rb
turnip_formatter-0.2.7 lib/turnip_formatter/printer/tab_tag_statistics.rb
turnip_formatter-0.2.6 lib/turnip_formatter/printer/tab_tag_statistics.rb
turnip_formatter-0.2.5 lib/turnip_formatter/printer/tab_tag_statistics.rb