Sha256: 819b1dc68c55136a079c4538424c7c800df1bfe844f64da1f90d98cac9e7a109

Contents?: true

Size: 1.3 KB

Versions: 44

Compression:

Stored size: 1.3 KB

Contents

module KnapsackPro
  class Tracker
    include Singleton

    attr_reader :global_time, :test_files_with_time
    attr_writer :current_test_path

    def initialize
      set_defaults
    end

    def reset!
      set_defaults
    end

    def start_timer
      @start_time = now_without_mock_time.to_f
    end

    def stop_timer
      @execution_time = now_without_mock_time.to_f - @start_time
      update_global_time
      update_test_file_time
      @execution_time
    end

    def current_test_path
      raise("current_test_path needs to be set by Knapsack Pro Adapter's bind method") unless @current_test_path
      @current_test_path.sub(/^\.\//, '')
    end

    def to_a
      test_files = []
      @test_files_with_time.each do |path, time_execution|
        test_files << {
          path: path,
          time_execution: time_execution
        }
      end
      test_files
    end

    private

    def set_defaults
      @global_time = 0
      @test_files_with_time = {}
      @test_path = nil
    end

    def update_global_time
      @global_time += @execution_time
    end

    def update_test_file_time
      @test_files_with_time[current_test_path] ||= 0
      @test_files_with_time[current_test_path] += @execution_time
    end

    def now_without_mock_time
      Time.now_without_mock_time
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
knapsack_pro-0.35.0 lib/knapsack_pro/tracker.rb
knapsack_pro-0.34.0 lib/knapsack_pro/tracker.rb
knapsack_pro-0.33.0 lib/knapsack_pro/tracker.rb
knapsack_pro-0.32.0 lib/knapsack_pro/tracker.rb
knapsack_pro-0.31.0 lib/knapsack_pro/tracker.rb
knapsack_pro-0.30.0 lib/knapsack_pro/tracker.rb
knapsack_pro-0.29.0 lib/knapsack_pro/tracker.rb
knapsack_pro-0.28.1 lib/knapsack_pro/tracker.rb
knapsack_pro-0.28.0 lib/knapsack_pro/tracker.rb
knapsack_pro-0.27.0 lib/knapsack_pro/tracker.rb
knapsack_pro-0.26.0 lib/knapsack_pro/tracker.rb
knapsack_pro-0.25.0 lib/knapsack_pro/tracker.rb
knapsack_pro-0.24.0 lib/knapsack_pro/tracker.rb
knapsack_pro-0.23.0 lib/knapsack_pro/tracker.rb
knapsack_pro-0.22.0 lib/knapsack_pro/tracker.rb
knapsack_pro-0.21.0 lib/knapsack_pro/tracker.rb
knapsack_pro-0.20.0 lib/knapsack_pro/tracker.rb
knapsack_pro-0.19.0 lib/knapsack_pro/tracker.rb
knapsack_pro-0.18.0 lib/knapsack_pro/tracker.rb
knapsack_pro-0.17.0 lib/knapsack_pro/tracker.rb