class Object

Public Instance Methods

changed_files_since_deploy() click to toggle source

this won't work until your capistrano supports fetching the currently deployed git SHA on production

# File lib/smokescreen/tasks.rb, line 33
def changed_files_since_deploy
  if File.exists?("log/latest-REVISION-syntaxcheck")
    revision = File.read("log/latest-REVISION-syntaxcheck").chomp

    `git whatchanged #{revision}..HEAD`.split("\n").select{|l| l =~ /^\:/}.collect {|l| l.split("\t")[1]}.sort.uniq
  else
    puts "log/latest-REVISION-syntaxcheck not found. run 'cap fetch_currently_deployed_version' to get it"
    []
  end
end
critical_test_files() click to toggle source
# File lib/smokescreen/tasks.rb, line 23
def critical_test_files
  Smokescreen.critical_tests
end
currently_changed_files() click to toggle source

file changes detected by git diff

# File lib/smokescreen/tasks.rb, line 45
def currently_changed_files
  `git status --porcelain`.split("\n").map{ |file| file.split.last }
end
functionals_changed(test_changed_files, t) click to toggle source

based on a list of files changes try to detect functional tests we should likely run include test files that were directly modified

# File lib/smokescreen/tasks.rb, line 56
def functionals_changed(test_changed_files, t)
  changed_controllers = []
  changed_functional_tests = []
  changed_view_directories = Set.new
  test_changed_files.each do |file|
    controller_match = file.match(/app\/controllers\/(.*).rb/)
    if controller_match
      changed_controllers << controller_match[1]
    end

    view_match = file.match(/app\/views\/(.*)\/.+\.erb/)
    if view_match
      changed_view_directories << view_match[1]
    end

    functional_test_match = file.match(/test\/functional\/(.*).rb/)
    if functional_test_match
      changed_functional_tests << functional_test_match[1]
    end
  end

  test_files = FileList['test/functional/**/*_test.rb'].select{|file| changed_controllers.any?{|controller| file.match(/test\/functional\/#{controller}_test.rb/) }} +
    FileList['test/functional/**/*_test.rb'].select{|file| changed_view_directories.any?{|view_directory| file.match(/test\/functional\/#{view_directory}_controller_test.rb/) }} +
    FileList['test/functional/**/*_test.rb'].select{|file|
    (changed_functional_tests.any?{|functional_test| file.match(/test\/functional\/#{functional_test}.rb/) } ||
     test_changed_files.any?{|changed_file| file==changed_file })
  }

  test_files = test_files.uniq
  test_files = test_files.reject{ |f| Smokescreen.critical_tests.include?(f) }

  t.libs << "test"
  t.verbose = true
  if !test_files.empty?
    t.test_files = test_files
  else
    t.test_files = []
  end
end
functionals_changed_tests(test_changed_files, t) click to toggle source

run tests against any functional test file, that has been modified

# File lib/smokescreen/tasks.rb, line 97
def functionals_changed_tests(test_changed_files, t)
  test_changed_files = test_changed_files.split("\n") if test_changed_files.is_a?(String)
  test_files = FileList['test/functional/**/*_test.rb'].select{|file| test_changed_files.any?{|changed_file| file==changed_file }}
  test_files = test_files.uniq
  test_files = test_files.reject{ |f| Smokescreen.critical_tests.include?(f) }

  t.libs << "test"
  t.verbose = true
  if !test_files.empty?
    t.test_files = test_files
  else
    t.test_files = []
  end
end
functionals_critical(test_changed_files, t) click to toggle source

Rake is so weird, but to define a task all code inside the task is evaluated at definition time This has lead to splitting out the methods, so that when defined they should really do nothing, but when invoked they should run and output info.

I am sure this means there is a better way to do this, but I don't know it

# File lib/smokescreen/tasks.rb, line 13
def functionals_critical(test_changed_files, t)
  t.libs << "test"
  t.verbose = true
  if !test_changed_files.empty?
    t.test_files = test_changed_files
  else
    t.test_files = []
  end
end
previously_changed_files() click to toggle source

file changes detected by git show

# File lib/smokescreen/tasks.rb, line 50
def previously_changed_files
  `git show --pretty="format:" --name-only`.split("\n")
end
units_changed(test_changed_files, t) click to toggle source

based on a list of files changes try to detect unit tests we should likely run. include test files that were directly modified

# File lib/smokescreen/tasks.rb, line 114
def units_changed(test_changed_files, t)
  changed_models = []
  test_changed_files.each do |file|
    matched = file.match(/app\/models\/(.*).rb/)
    if matched
      changed_models << matched[1]
    end
  end
  test_files = FileList['test/unit/*_test.rb'].select{|file| 
    (changed_models.any?{|model| file.match(/test\/unit\/#{model}_test.rb/) } ||
     test_changed_files.any?{|changed_file| file==changed_file })
  }
  test_files = test_files.uniq

  t.libs << "test"
  t.verbose = true
  if !test_files.empty?
    t.test_files = test_files
  else
    t.test_files = []
  end
end
units_changed_tests(test_changed_files, t) click to toggle source

run tests against any unit test file, that has been modified

# File lib/smokescreen/tasks.rb, line 138
def units_changed_tests(test_changed_files, t)
  test_changed_files = test_changed_files.split("\n") if test_changed_files.is_a?(String)
  test_files = FileList['test/unit/*_test.rb'].select{|file| test_changed_files.any?{|changed_file| file==changed_file }}
  test_files = test_files.uniq

  t.libs << "test"
  t.verbose = true
  if !test_files.empty?
    t.test_files = test_files
  else
    t.test_files = []
  end
end