Module: Executor

Defined in:
lib/specss/executor.rb

Class Method Summary collapse

Class Method Details

.condensedObject



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

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

.extendedObject



51
52
53
54
# File 'lib/specss/executor.rb', line 51

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



28
29
30
31
32
33
34
35
36
# File 'lib/specss/executor.rb', line 28

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



40
41
42
43
44
45
46
47
48
49
# File 'lib/specss/executor.rb', line 40

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



62
63
64
65
# File 'lib/specss/executor.rb', line 62

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
# File 'lib/specss/executor.rb', line 8

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

  return false unless $changed_files

  # 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



67
68
69
70
71
72
73
74
75
# File 'lib/specss/executor.rb', line 67

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