Class | Autotest |
In: |
lib/autotest.rb
|
Parent: | Object |
Autotest continuously scans the files in your project for changes and runs the appropriate tests. Test failures are run until they have all passed. Then the full test suite is run to ensure that nothing else was inadvertantly broken.
If you want Autotest to start over from the top, hit ^C once. If you want Autotest to quit, hit ^C twice.
The autotest command will automatically discover a Rails directory by looking for config/environment.rb. When Rails is discovered, autotest uses RailsAutotest to perform file mappings and other work. See RailsAutotest for details.
Plugins:
Plugins are available by creating a .autotest file either in your project root or in your home directory. You can then write event handlers in the form of:
Autotest.add_hook hook_name { |autotest| ... }
The available hooks are: initialize, run, run_command, ran_command,
red, green, updated, all_good, reset, interrupt, and quit.
See example_dot_autotest.rb for more details.
If a hook returns a true value, it signals to autotest that the hook was handled and should not continue executing hooks.
Naming:
Autotest uses a simple naming scheme to figure out how to map implementation files to test files following the Test::Unit naming scheme.
Strategy:
T0 | = | Time.at 0 |
ALL_HOOKS | = | [ :all_good, :initialize, :interrupt, :quit, :ran_command, :reset, :run_command, :waiting ] |
HOOKS | = | Hash.new { |h,k| h[k] = [] } |
WINDOZE | = | /win32/ =~ RUBY_PLATFORM |
SEP | = | WINDOZE ? '&' : ';' |
completed_re | [RW] | |
extra_class_map | [RW] | |
extra_files | [RW] | |
failed_results_re | [RW] | |
files_to_test | [RW] | |
find_directories | [RW] | |
find_order | [RW] | |
interrupted | [RW] | |
known_files | [W] | |
last_mtime | [RW] | |
libs | [RW] | |
order | [RW] | |
output | [RW] | |
results | [RW] | |
sleep | [RW] | |
tainted | [RW] | |
unit_diff | [RW] | |
wants_to_quit | [RW] |
Automatically find all potential autotest runner styles by searching your loadpath, vendor/plugins, and rubygems for "autotest/discover.rb". If found, that file is loaded and it should register discovery procs with autotest using add_discovery. That proc should return one or more strings describing the user‘s current environment. Those styles are then combined to dynamically invoke an autotest plugin to suite your environment. That plugin should define a subclass of Autotest with a corresponding name.
Autotest.add_discovery do "rails" if File.exist? 'config/environment.rb' end
Adds regexp to the list of exceptions for find_file. This must be called before the exceptions are compiled.
Adds a file mapping. regexp should match a file path in the codebase. proc is passed a matched filename and Regexp.last_match. proc should return an array of tests to run.
For example, if test_helper.rb is modified, rerun all tests:
at.add_mapping(/test_helper.rb/) do |f, _| at.files_matching(/^test.*rb$/) end
Clears the list of exceptions for find_file. This must be called before the exceptions are compiled.
Clears all file mappings. This is DANGEROUS as it entirely disables autotest. You must add at least one file mapping that does a good job of rerunning appropriate tests.
Return a compiled regexp of exceptions for find_files or nil if no filtering should take place. This regexp is generated from exception_list.
Find the files to process, ignoring temporary files, source configuration management files, etc., and return a Hash mapping filename to modification time.
Find the files which have been modified, update the recorded timestamps, and use this to update the files to test. Returns true if any file is newer than the previously recorded most recent file.
Removes regexp to the list of exceptions for find_file. This must be called before the exceptions are compiled.