Module: Executor

Defined in:
lib/specss/executor.rb

Class Method Summary collapse

Class Method Details

.condensedObject



60
61
62
# File 'lib/specss/executor.rb', line 60

def condensed
  Files::Specs.get_specs($changed_files)
end

.extendedObject



55
56
57
58
# File 'lib/specss/executor.rb', line 55

def extended
  all_files = get_all_affected_files
  Files::Specs.get_specs(all_files)
end

.get_all_affected_filesObject

Returns all unique files in changelist and their dependents



32
33
34
35
36
37
38
39
40
# File 'lib/specss/executor.rb', line 32

def get_all_affected_files
  all_files = $changed_files
  dependents = get_dependents

  dependents.each do |d|
    all_files.push(d) unless all_files.include? d
  end
  all_files
end

.get_dependentsObject

Returns all dependents of files in changelist



44
45
46
47
48
49
50
51
52
53
# File 'lib/specss/executor.rb', line 44

def get_dependents
  dependents = []
  $changed_files.each do |f|
    dependents_array = Files::Dependencies.get_dependencies(f)
    dependents_array.each do |d|
      dependents.push(d) unless dependents.include? d
    end
  end
  dependents
end

.list_specsObject

Prints a list of specs for files opened for edit



66
67
68
69
# File 'lib/specss/executor.rb', line 66

def list_specs
  specs = condensed
  puts specs.join("\n")
end

.main(opt) ⇒ Object

Takes in option from parse and executes main functions



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/specss/executor.rb', line 8

def main(opt)
  $changed_files = Files::Perforce.get_changelist_files

  if $changed_files.include? 'p4: command not found'
    puts 'Please install perforce command line client: '\
         'https://www.perforce.com/perforce/r14.2/manuals/p4guide/chapter.install.html'
    return false
  end

  # Pass in options from ARGV on whether to run lite or extended
  case opt
  when 'extended'
    specs_to_run = extended
  when 'list'
    list_specs
  else
    specs_to_run = condensed
  end

  run_specs(specs_to_run) unless opt == 'list'
end

.run_specs(specs_to_run) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'lib/specss/executor.rb', line 71

def run_specs(specs_to_run)
  if specs_to_run.empty?
    puts 'No specs need to be run'
  else
    spec_names = Files::Specs.chop_file_paths(specs_to_run)
    puts 'Running specs: ' + spec_names.join(" ")
    exec "bundle exec rspec " + specs_to_run.join(" ")
  end
end