Class: Autotest::Rails

Inherits:
Autotest
  • Object
show all
Defined in:
lib/autotest/rails.rb

Constant Summary collapse

VERSION =
'4.2.1'

Instance Method Summary collapse

Constructor Details

#initializeRails

:nodoc:



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
# File 'lib/autotest/rails.rb', line 6

def initialize # :nodoc:
  super

  add_exception %r%^\./(?:db|doc|log|public|script|tmp|vendor)%

  clear_mappings

  add_mapping %r%^lib/(.*)\.rb$% do |_, m|
    files_matching %r%^test/(lib|unit/lib)/#{m[1]}.*_test.rb$%
    # TODO: (unit|functional|integration) maybe?
  end

  add_mapping %r%^test/fixtures/(.*)s.yml% do |_, m|
    files_matching %r%^test/(models|controllers|views|unit|functional)/#{m[1]}.*_test.rb$%
  end

  add_mapping %r%^test/.*_test\.rb$% do |filename, _|
    filename
  end

  add_mapping %r%^app/models/(.*)\.rb$% do |_, m|
    files_matching %r%^test/(models|unit)/#{m[1]}.*_test.rb$%
  end

  add_mapping %r%^app/helpers/(.*)_helper.rb% do |_, m|
    if m[1] == "application" then
      files_matching %r%^test/(helpers|controllers|views|unit/helpers/functional)/.*_test\.rb$%
    else
      files_matching %r%^test/(helpers|controllers|views|unit/helpers/functional)/#{m[1]}.*_test.rb$%
    end
  end

  add_mapping %r%^app/views/(.*)/% do |_, m|
    files_matching %r%^test/(controllers|views|functional)/#{m[1]}.*_test.rb$%
  end

  add_mapping %r%^app/controllers/(.*)\.rb$% do |_, m|
    if m[1] == "application" then
      files_matching %r%^test/(controllers|views|functional)/.*_test\.rb$%
    else
      files_matching %r%^test/(controllers|views|functional)/#{m[1]}.*_test.rb$%
    end
  end

  add_mapping %r%^app/views/layouts/% do
    "test/views/layouts_view_test.rb"
  end

  add_mapping %r%^test/test_helper.rb|config/((boot|environment(s/test)?).rb|database.yml|routes.rb)% do
    files_matching %r%^test/(models|controllers|views|unit|functional)/.*_test.rb$%
  end
end

Instance Method Details

#path_to_classname(s) ⇒ Object

Convert the pathname s to the name of class.



60
61
62
63
64
65
66
# File 'lib/autotest/rails.rb', line 60

def path_to_classname(s)
  sep = File::SEPARATOR
  f = s.sub(/^test#{sep}((\w+)#{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