summaryrefslogtreecommitdiff
path: root/lib/tasks/spinach.rake
blob: 01d23b89bb7e5fe892688d73aec17dff8436573b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Rake::Task["spinach"].clear if Rake::Task.task_defined?('spinach')

namespace :spinach do
  namespace :project do
    desc "GitLab | Spinach | Run project commits, issues and merge requests spinach features"
    task :half do
      run_spinach_tests('@project_commits,@project_issues,@project_merge_requests')
    end

    desc "GitLab | Spinach | Run remaining project spinach features"
    task :rest do
      run_spinach_tests('~@admin,~@dashboard,~@profile,~@public,~@snippets,~@project_commits,~@project_issues,~@project_merge_requests')
    end
  end

  desc "GitLab | Spinach | Run project spinach features"
  task :project do
    run_spinach_tests('~@admin,~@dashboard,~@profile,~@public,~@snippets')
  end

  desc "GitLab | Spinach | Run other spinach features"
  task :other do
    run_spinach_tests('@admin,@dashboard,@profile,@public,@snippets')
  end

  desc "GitLab | Spinach | Run other spinach features"
  task :builds do
    run_spinach_tests('@builds')
  end
end

desc "GitLab | Run spinach"
task :spinach do
  run_spinach_tests(nil)
end

def run_command(cmd)
  system({'RAILS_ENV' => 'test', 'force' => 'yes'}, *cmd)
end

def run_spinach_command(args)
  run_command(%w(spinach -r rerun) + args)
end

def run_spinach_tests(tags)
  #run_command(%w(rake gitlab:setup)) or raise('gitlab:setup failed!')

  success = run_spinach_command(%W(--tags #{tags}))
  3.times do |_|
    break if success
    break unless File.exists?('tmp/spinach-rerun.txt')

    tests = File.foreach('tmp/spinach-rerun.txt').map(&:chomp)
    puts ''
    puts "Spinach tests for #{tags}: Retrying tests... #{tests}".red
    puts ''
    sleep(3)
    success = run_spinach_command(tests)
  end

  raise("spinach tests for #{tags} failed!") unless success
end