public
Description: A starting point for your new Rails project.
Clone URL: git://github.com/relevance/jumpstart.git
jumpstart / .autotest
100644 86 lines (66 sloc) 2.698 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
Autotest.add_hook :initialize do |autotest|
  autotest.clear_exceptions
  autotest.clear_mappings
  
  autotest.add_exception %r%^\./(?:doc|log|public|script|tmp|vendor)%
  %w{.svn .hg .git}.each {|exception| autotest.add_exception(exception)}
  
  helper = AutotestUnitRecord.new(autotest, ENV)
  helper.setup_autotest
end
 
class AutotestUnitRecord
  attr_accessor :autotest, :run_mode
  
  def initialize(autotest, environment)
    @autotest = autotest
    @run_mode = (environment["AUTOTEST"] == "functional") ? :functional : :unit
  end
  
  def any_matching_tests(class_file)
    autotest.files_matching %r%^test/#{run_mode}/?(models|controllers|helpers)?/?#{class_file}s?(_view|_helper|_controller)?_test\.rb$%
    
    # ["test/#{run_mode}/models/#{class_file}s?_test.rb",
    # "test/#{run_mode}/controllers/#{class_file}s?_controller_test.rb",
    # "test/#{run_mode}/views/#{class_file}s?_view_test.rb"]
  end
 
  def all_tests autotest
    autotest.files_matching %r%^test/#{run_mode}/.*_test\.rb$%
  end
 
  def setup_autotest
    puts "Running autotest for #{run_mode} tests in a unit_record app."
    autotest.add_mapping(%r%^test/fixtures/(.*)s.yml%) { |_, m|
      any_matching_tests(m[1])
    }
 
    autotest.add_mapping(/^lib\/.*\.rb$/) do |filename, _|
      impl = File.basename(filename, '.rb')
      any_matching_tests(impl)
    end
 
    autotest.add_mapping %r%^test/fixtures/(.*)s.yml% do |_, m|
      any_matching_tests(m[1])
    end
 
    autotest.add_mapping %r%^test/#{run_mode}/.*rb$% do |filename, _|
      filename
    end
 
    autotest.add_mapping %r%^app/models/(.*)\.rb$% do |_, m|
      any_matching_tests(m[1])
    end
 
    autotest.add_mapping %r%^app/helpers/application_helper.rb% do
      autotest.files_matching %r%^test/#{run_mode}/helpers/.*_test\.rb$%
    end
 
    autotest.add_mapping %r%^app/helpers/(.*)_helper.rb% do |_, m|
      if m[1] == "application" then
        autotest.files_matching %r%^test/#{run_mode}/helpers/.*_test\.rb$%
      else
        autotest.files_matching %r%^test/#{run_mode}/helpers/#{m[1]}_helper_test\.rb$%
      end
    end
 
    autotest.add_mapping %r%^app/controllers/(.*)\.rb$% do |_, m|
      if m[1] == "application" then
        autotest.files_matching %r%^test/#{run_mode}/controllers/.*_test\.rb$%
      else
        autotest.files_matching %r%^test/#{run_mode}/controllers/#{m[1]}_test\.rb$%
      end
    end
 
    autotest.add_mapping %r%^config/routes.rb$% do # FIX:
      autotest.files_matching %r%^test/controllers/.*_test\.rb$%
    end
 
    autotest.add_mapping %r%^test/.*test_helper.rb|db/example_data.rb|config/((boot|environment(s/test)?).rb|database.yml)% do
      all_tests autotest
    end
 
  end
  
end