BigW Consortium Gitlab

spinach.rake 1.66 KB
Newer Older
1
Rake::Task["spinach"].clear if Rake::Task.task_defined?('spinach')
2

3
namespace :spinach do
4 5 6
  namespace :project do
    desc "GitLab | Spinach | Run project commits, issues and merge requests spinach features"
    task :half do
Kamil Trzcinski committed
7
      run_spinach_tests('@project_commits,@project_issues,@project_merge_requests')
8 9 10 11
    end

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

16 17
  desc "GitLab | Spinach | Run project spinach features"
  task :project do
Kamil Trzcinski committed
18
    run_spinach_tests('~@admin,~@dashboard,~@profile,~@public,~@snippets')
19
  end
20

21 22
  desc "GitLab | Spinach | Run other spinach features"
  task :other do
Kamil Trzcinski committed
23 24 25 26 27 28
    run_spinach_tests('@admin,@dashboard,@profile,@public,@snippets')
  end

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

32 33
desc "GitLab | Run spinach"
task :spinach do
Kamil Trzcinski committed
34 35 36
  run_spinach_tests(nil)
end

37
def run_system_command(cmd)
38
  system({ 'RAILS_ENV' => 'test', 'force' => 'yes' }, *cmd)
39
end
40

Kamil Trzcinski committed
41
def run_spinach_command(args)
42
  run_system_command(%w(spinach -r rerun) + args)
Kamil Trzcinski committed
43 44 45 46 47 48
end

def run_spinach_tests(tags)
  success = run_spinach_command(%W(--tags #{tags}))
  3.times do |_|
    break if success
49
    break unless File.exist?('tmp/spinach-rerun.txt')
Kamil Trzcinski committed
50 51 52

    tests = File.foreach('tmp/spinach-rerun.txt').map(&:chomp)
    puts ''
53
    puts "Spinach tests for #{tags}: Retrying tests... #{tests}".color(:red)
Kamil Trzcinski committed
54 55 56
    puts ''
    sleep(3)
    success = run_spinach_command(tests)
57
  end
Kamil Trzcinski committed
58 59

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