Class: Cucumber::Cli::ProfileLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber_in_groups.rb

Overview

this class handles cucumber.yml loading - we monkey-patch it

Instance Method Summary collapse

Instance Method Details

#grouped_features(*args) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cucumber_in_groups.rb', line 14

def grouped_features(*args)
  # default argument
  args << "features" if args.empty?

  # USAGE: GROUP=1of2 rake cucumber:ci
  # OR:    GROUP=2of2 rake cucumber:ci
  if ENV["GROUP"]
    if ENV["GROUP"] =~ /^(\d+)of(\d+)$/
      group = $1.to_i
      groups_count = $2.to_i
      if group > 0 and group <= groups_count
        # listing content of features folder (or whatever folder requested)
        features = list_features(args).sort
        files_to_test = features.in_groups(groups_count, false)[group-1]

        if ENV['DEBUG']
          STDERR.puts "\n=========== FEATURES GROUP #{group} of #{groups_count} ============="
          STDERR.puts files_to_test.inspect
          STDERR.puts "==============================================="
        end

        # returning files array to cucumber.yml
        files_to_test.join(" ")
      else
        raise "Invalid value of GROUP env variable (#{ENV['GROUP']}). First number should be in 1..#{groups_count} range"
      end
    else
      raise "Invalid value of GROUP env variable (#{ENV['GROUP']}). Expected e.g. GROUP=1of2"
    end
  else
    args.join(" ")
  end
end

#list_features(paths) ⇒ Object



48
49
50
# File 'lib/cucumber_in_groups.rb', line 48

def list_features(paths)
  paths.map { |path| Dir["#{path}/**/*.feature"] }.flatten
end