public
Description: Use autotest on your rails plugin development.
Homepage:
Clone URL: git://github.com/metaskills/autotest_railsplugin.git
autotest_railsplugin / railsplugin.rb
100644 54 lines (38 sloc) 1.704 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class Autotest::Railsplugin < Autotest
  
  def initialize
    super
    
    # Default libs for autotest. So far they suit us just fine.
    # self.libs = %w[. lib test].join(File::PATH_SEPARATOR)
    
    # Ignore these directories in the plugin.
    add_exception %r%^\./(?:autotest|tasks)%
# Ignore these ruby files in the root of the plugin folder.
add_exception %r%^\./(install|uninstall)\.rb$%
# Ignore these misc files in the root of the plugin folder.
add_exception %r%^\./(.*LICENSE|Rakefile|README.*|CHANGELOG.*)$%i
# Ignore any log file.
add_exception %r%.*\.log$%
clear_mappings
# Easy start. Any test file saved runs that file
self.add_mapping(%r%^test/.*_test.rb$%) do |filename, matchs|
filename
end
# If any file in lib matches up to a file in the same directory structure of
# the test directory, ofcourse having _test.rb at the end, will run that test.
self.add_mapping(%r%^lib/(.*)\.rb$%) do |filename, matchs|
filename_path = matchs[1]
files_matching %r%^test/#{filename_path}_test\.rb$%
end
# If any core test file like the helper, boot, database.yml change, then run
# all matching .*_test.rb files in the test directory.
add_mapping %r%^test/(boot|helper|test_helper|factories)\.rb|database.yml% do
files_matching %r%^test/.*_test\.rb$%
    end
    
  end
  
  def path_to_classname(s)
    sep = File::SEPARATOR
    f = s.sub(/^test#{sep}?/, '').sub(/\.rb$/, '').split(sep)
    f = f.map { |path| path.split(/_/).map { |seg| seg.capitalize }.join }
    # f = f.map { |path| path =~ /Test$/ ? path : "#{path}Test" }
    f.join('::')
  end
  
  
end