Sha256: 68bdea3b348353f170332b2fd72478b6e8abf41cf89552c37f96aaa7beb3dea4

Contents?: true

Size: 1.57 KB

Versions: 6

Compression:

Stored size: 1.57 KB

Contents

require 'cucumber/ast/scenario_outline'

module UglyFace
  module Formatter
    module ViewHelper

      def start_time
        @tests_started.strftime("%a %B %-d, %Y at %H:%M:%S")
      end

      def step_count
        @step_mother.steps.length
      end

      def scenario_count
        @step_mother.scenarios.length
      end

      def total_duration
        @duration
      end

      def step_average_duration(features)
        scenarios = features.collect { |feature| feature.scenarios }
        steps = scenarios.flatten.collect { |scenario| scenario.steps }
        durations = steps.flatten.collect { |step| step.duration }
        format_duration get_average_from_float_array durations
      end

      def scenario_average_duration(features)
        scenarios = features.collect { |feature| feature.scenarios }
        durations = scenarios.flatten.collect { |scenario| scenario.duration }
        format_duration get_average_from_float_array durations
      end

      def scenarios_summary_for(status)
        summary_percent(@step_mother.scenarios(status).length, scenario_count)
      end

      def steps_summary_for(status)
        summary_percent(@step_mother.steps(status).length, step_count)
      end

      def failed_scenario?(scenario)
        scenario.status == :failed
      end


      private

      def get_average_from_float_array(arr)
        arr.reduce(:+).to_f / arr.size
      end

      def summary_percent(number, total)
        percent = (number.to_f / total) * 100
        "#{number} <span class=\"percentage\">(#{'%.1f' % percent}%)</span>"
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ugly_face-0.6 lib/ugly_face/formatter/view_helper.rb
ugly_face-0.5 lib/ugly_face/formatter/view_helper.rb
ugly_face-0.4 lib/ugly_face/formatter/view_helper.rb
ugly_face-0.3 lib/ugly_face/formatter/view_helper.rb
ugly_face-0.2 lib/ugly_face/formatter/view_helper.rb
ugly_face-0.1 lib/ugly_face/formatter/view_helper.rb