Class: Saucer::Parallel

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opt = {}) ⇒ Parallel

Returns a new instance of Parallel.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/saucer/parallel.rb', line 9

def initialize(opt = {})
  @number = opt[:number] || ENV['PARALLEL_PROCESSES']
  @path = opt[:path] || ENV['TEST_PATH'] || "spec"
  @output = opt[:output] || ENV['REPORT_OUTPUT'] || 'output'
  @platforms = opt[:platforms] || []
  if File.exist?('configs/platform_configs.yml')
    yaml = YAML.load_file('configs/platform_configs.yml')
    @platforms ||= yaml.map { |c| Saucer::PlatformConfiguration.new(c) }
  end
  @success = true
end

Instance Attribute Details

#numberObject

Returns the value of attribute number.



7
8
9
# File 'lib/saucer/parallel.rb', line 7

def number
  @number
end

#outputObject

Returns the value of attribute output.



7
8
9
# File 'lib/saucer/parallel.rb', line 7

def output
  @output
end

#pathObject

Returns the value of attribute path.



7
8
9
# File 'lib/saucer/parallel.rb', line 7

def path
  @path
end

Instance Method Details

#execute_testObject



46
47
48
49
50
51
52
53
54
55
# File 'lib/saucer/parallel.rb', line 46

def execute_test
  if path.include?('spec')
    ENV['PARALLEL_SPLIT_TEST_PROCESSES'] = number.to_s if number
    system "parallel_split_test #{path} --out #{@output}.xml"
  elsif path.include?('features')
    system "parallel_cucumber #{path} -o \"--format junit --out #{@output} --format pretty\" -n #{number.to_s}"
  else
    raise ArgumentError, "Unable to determine if using rspec or cucumber"
  end
end

#runObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/saucer/parallel.rb', line 21

def run
  if @platforms.empty?
    raise StandardError, "Tests failed!" unless execute_test
    return
  end

  @platforms.each do |platform|
    Rake::Task.define_task(platform.name) {
      ENV['platform'] = platform.to_hash[:platform]
      ENV['browser_name'] = platform.to_hash[:browserName]
      ENV['version'] = platform.to_hash[:version]

      begin
        @result = execute_test
      ensure
        @success &= @result
      end
    }
  end

  Rake::MultiTask.define_task(sauce_tests: @platforms.map(&:name)) {
    raise StandardError, "Tests failed!" unless @success
  }.invoke
end