diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..97e104d --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "bundle/nerdcommenter"] + path = bundle/nerdcommenter + url = git://github.com/scrooloose/nerdcommenter.git diff --git a/lib/tconsole/server.rb b/lib/tconsole/server.rb index 04c4de3..f0c9e0d 100644 --- a/lib/tconsole/server.rb +++ b/lib/tconsole/server.rb @@ -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