Class: SpecDependencies

Inherits:
Object show all
Defined in:
rake_modules/specdeps.rb

Instance Method Summary collapse

Constructor Details

#initializeSpecDependencies

Finds all specs to run based on the changed modules.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'rake_modules/specdeps.rb', line 4

def initialize
  @deps = {}
  # Scan all the modules that have spec tests and dependencies
  # from other modules (thus have a .fixtures.yaml file),
  # read the contents of the fixtures file and create a
  # one-level dependency tree. It could be debatable if we should
  # include higher order, indirect dependencies (if module C depends on module
  # B that depends on module A, should we add it to the dependencies of C?),
  # but we chose not to go that way as each module should just care about the
  # interfaces it uses directly.
  FileList["modules/*/.fixtures.yml"].each do |file|
    module_name = module_from_filename(file)
    symlinks = YAML.safe_load(File.open(file))['fixtures']['symlinks'].keys.select{ |x| x != module_name }
    symlinks.each do |dependency|
      @deps[dependency] ||= []
      @deps[dependency] << module_name
    end
  end
end

Instance Method Details

#files_with_own_tox(filelist) ⇒ Object



52
53
54
55
56
57
58
59
# File 'rake_modules/specdeps.rb', line 52

def files_with_own_tox(filelist)
  # Given a list of files, get the list of
  # files that have a tox.ini file in their
  # module.
  filelist.select do |file|
    File.exists? "modules/#{module_from_filename(file)}/tox.ini"
  end
end

#specs_to_run(filelist) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'rake_modules/specdeps.rb', line 24

def specs_to_run(filelist)
  # Extract a list of specs to run. For each module touched by the current
  # change, we add all its dependencies and the module itself only if it has a
  # spec to run
  specs = Set.new
  modules = modules_modified(filelist)
  return [] unless modules
  modules.each do |mod|
    specs.add(mod) if Dir.exists?("modules/#{mod}/spec")
    if @deps.include?mod
      @deps[mod].each{ |m| specs.add(m) if Dir.exists?("modules/#{m}/spec") }
    end
  end
  specs.to_a
end

#tox_to_run(filelist) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'rake_modules/specdeps.rb', line 40

def tox_to_run(filelist)
  # Scan all the modules with a changed python file for tox.ini,
  # and return them as a list of modules
  mods_to_test = Set.new
  modules = modules_modified(filelist)
  return [] unless modules
  modules.each do |mod|
    mods_to_test.add(mod) if File.exists? "modules/#{mod}/tox.ini"
  end
  mods_to_test
end