Sha256: b1b6f503260bb331c3c4f593f92e6410591510bd99a351c4cb09a22e2d896d85

Contents?: true

Size: 997 Bytes

Versions: 19

Compression:

Stored size: 997 Bytes

Contents

# frozen_string_literal: true

module KnapsackPro
  module TestCaseMergers
    class RSpecMerger < BaseMerger
      def call
        merged_test_files_hash = {}
        test_files.each do |test_file|
          test_file_path = extract_test_file_path(test_file.fetch('path'))

          # must be float (default type for time execution from API)
          merged_test_files_hash[test_file_path] ||= 0.0
          merged_test_files_hash[test_file_path] += test_file.fetch('time_execution')
        end

        merged_test_files = []
        merged_test_files_hash.each do |path, time_execution|
          merged_test_files << {
            'path' => path,
            'time_execution' => time_execution
          }
        end
        merged_test_files
      end

      private

      # path - can be:
      # test file path: spec/a_spec.rb
      # or test example path: spec/a_spec.rb[1:1]
      def extract_test_file_path(path)
        path.gsub(/\.rb\[.+\]$/, '.rb')
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
knapsack_pro-7.10.0 lib/knapsack_pro/test_case_mergers/rspec_merger.rb
knapsack_pro-7.9.0 lib/knapsack_pro/test_case_mergers/rspec_merger.rb
knapsack_pro-7.8.2 lib/knapsack_pro/test_case_mergers/rspec_merger.rb
knapsack_pro-7.8.1 lib/knapsack_pro/test_case_mergers/rspec_merger.rb
knapsack_pro-7.8.0 lib/knapsack_pro/test_case_mergers/rspec_merger.rb
knapsack_pro-7.7.0 lib/knapsack_pro/test_case_mergers/rspec_merger.rb
knapsack_pro-7.6.2 lib/knapsack_pro/test_case_mergers/rspec_merger.rb
knapsack_pro-7.6.1 lib/knapsack_pro/test_case_mergers/rspec_merger.rb
knapsack_pro-7.6.0 lib/knapsack_pro/test_case_mergers/rspec_merger.rb
knapsack_pro-7.1.0 lib/knapsack_pro/test_case_mergers/rspec_merger.rb
knapsack_pro-7.0.1 lib/knapsack_pro/test_case_mergers/rspec_merger.rb
knapsack_pro-7.0.0 lib/knapsack_pro/test_case_mergers/rspec_merger.rb
knapsack_pro-6.0.4 lib/knapsack_pro/test_case_mergers/rspec_merger.rb
knapsack_pro-6.0.3 lib/knapsack_pro/test_case_mergers/rspec_merger.rb
knapsack_pro-6.0.2 lib/knapsack_pro/test_case_mergers/rspec_merger.rb
knapsack_pro-6.0.1 lib/knapsack_pro/test_case_mergers/rspec_merger.rb
knapsack_pro-6.0.0 lib/knapsack_pro/test_case_mergers/rspec_merger.rb
knapsack_pro-5.7.0 lib/knapsack_pro/test_case_mergers/rspec_merger.rb
knapsack_pro-5.6.0 lib/knapsack_pro/test_case_mergers/rspec_merger.rb