Skip to content

Commit

Permalink
Working on adding recent command.
Browse files Browse the repository at this point in the history
  • Loading branch information
nalanj committed Dec 15, 2011
1 parent 13ffd43 commit 6b69b2b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule "bundle/nerdcommenter"]
path = bundle/nerdcommenter
url = git://github.com/scrooloose/nerdcommenter.git
33 changes: 33 additions & 0 deletions lib/tconsole/server.rb
Expand Up @@ -58,5 +58,38 @@ def run_tests(globs)
puts "Test time (including load): #{time}s"
puts
end

# This code is from the rails test:recents command
def run_recents
touched_since = Time.now - 600 # 10 minutes ago
files = recent_files(touched_since, "app/models/**/*.rb", "test/unit")
files.concat(recent_files(touched_since, "app/controllers/**/*.rb", "test/functional"))

run_tests(files)
end

def recent_files(touched_since, source_pattern, test_path)
Dir.glob(source_pattern).map do |path|
if File.mtime(path) > touched_since
tests = []
source_dir = File.dirname(path).split("/")
source_file = File.basename(path, '.rb')

# Support subdirs in app/models and app/controllers
modified_test_path = source_dir.length > 2 ? "#{test_path}/" << source_dir[1..source_dir.length].join('/') : test_path

# For modified files in app/ run the tests for it. ex. /test/functional/account_controller.rb
test = "#{modified_test_path}/#{source_file}_test.rb"
tests.push test if File.exist?(test)

# For modified files in app, run tests in subdirs too. ex. /test/functional/account/*_test.rb
test = "#{modified_test_path}/#{File.basename(path, '.rb').sub("_controller","")}"
File.glob("#{test}/*_test.rb").each { |f| tests.push f } if File.exist?(test)

return tests

end
end.flatten.compact
end
end
end

0 comments on commit 6b69b2b

Please sign in to comment.