Class: Railscheck::Test::Project

Inherits:
Railscheck::TestCase show all
Defined in:
lib/test/tc_project.rb

Instance Method Summary collapse

Methods inherited from Railscheck::TestCase

#default_test

Instance Method Details

#test_plugins_validObject

test that installed plugins have the required minimum file structure.



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/test/tc_project.rb', line 93

def test_plugins_valid
  Dir["#{RAILS_ROOT}/vendor/plugins/*"].each do |plugindir|
    assert File.directory?(plugindir), "Error - \"#{plugindir}\" is not a directory. Project vendor directory may only contain directories."
    
    lib_dir = File.join(plugindir, "lib")
    init_file = File.join(plugindir, "init.rb")
    
    warn "No lib sub-directory in plugin at \"#{plugindir}\"" if !File.directory?(lib_dir)          
    warn "No init file in plugin at \"#{plugindir}\"" if !File.file?(init_file)
  end
end

#test_rails_projectObject

Verify rails project structure/files taking into account various rails versions, build-in test/rspec usage etc.



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
87
88
89
90
# File 'lib/test/tc_project.rb', line 7

def test_rails_project
   root = RAILS_ROOT
  
   # Check for key rails 1.0+ directories that must exist for all complete and valid projects (skip optional ones):
   ["#{root}/app", "#{root}/app/controllers", "#{root}/app/helpers", "#{root}/app/models", "#{root}/app/views", "#{root}/app/views/layouts",
    "#{root}/config", "#{root}/config/environments",
    "#{root}/db", 
    "#{root}/lib", "#{root}/lib/tasks",
    "#{root}/log", 
    "#{root}/public", "#{root}/public/images", "#{root}/public/javascripts","#{root}/public/stylesheets",
    "#{root}/script", "#{root}/script/performance", "#{root}/script/process",
    "#{root}/vendor", "#{root}/vendor/plugins"
   ].each do |dir|
    assert File.directory?(dir), "Error - missing rails directory #{dir}"
   end
   
   # Check for key rails 2.0+ directories that must exist for all complete and valid projects (skip optional ones):
   if Rails::VERSION::MAJOR >=2
     ["#{root}/config/initializers"
     ].each do |dir|
       assert File.directory?(dir), "Error - missing rails directory #{dir}"
     end
   end
   
   # Build-in test or rspec can be used so we need to verify which one (or both) is used.
   test = File.directory?("#{root}/test")
   rspec = File.directory?("#{root}/spec")
   
   # Check that build-in test or rspec test directories exist.
   assert test || rspec, "Either test or spec directories should exist for testing purposes. Both are missing."
   
   # Check for build-in test directories (may not all exist so issue warnings only)
   if test
    ["#{root}/test/fixtures", "#{root}/test/functional", "#{root}/test/integration", 
     "#{root}/test/mocks", "#{root}/test/mocks/development", "#{root}/test/mocks/test",
    ].each do |dir|
      "Missing rails directory #{dir}" if !File.directory?(dir)
    end
   end

   # Check for rspec directories (may not all exist so issue warnings only)       
   if rspec
    [ #TODO: Add any expected directories here.
    ].each do |dir|
      "Missing rails rspec directory #{dir}" if !File.directory?(dir)
    end
   end

   # Check for vital rails 1.0+ files that must exist for all complete and valid projects (skip optional ones):
   ["#{root}/app/controllers/application.rb",
    "#{root}/config/boot.rb", "#{root}/config/database.yml", "#{root}/config/environment.rb", "#{root}/config/routes.rb",
    "#{root}/config/environments/development.rb", "#{root}/config/environments/test.rb", "#{root}/config/environments/production.rb",
    "#{root}/script/about", "#{root}/script/console", "#{root}/script/console", "#{root}/script/destroy", "#{root}/script/generate",
    "#{root}/script/plugin", "#{root}/script/runner", "#{root}/script/server",
    "#{root}/script/performance/benchmarker", "#{root}/script/performance/profiler",
    "#{root}/script/process/inspector", "#{root}/script/process/reaper", "#{root}/script/process/spawner",
   ].each do |file|
    assert File.file?(file), "Error - missing rails file #{file}"
  end
  
   # Check for vital rails 2.0+ files that must exist for all complete and valid projects (skip optional ones):
   if Rails::VERSION::MAJOR >=2
     [ #TODO: Add any rails 2.x only files here
     ].each do |file|
      assert File.file?(file), "Error - missing rails file #{file}"
    end
  end
  
  # Check for optional build-in test files.        
  if test
     ["#{root}/test/test_helper.rb"
     ].each do |file|
      warn "Missing rails file #{file}" if !File.file?(file) 
    end
  end
  
  # Check for optional rspec files.        
  if rspec
     ["#{root}/spec/spec_helper.rb"
     ].each do |file|
      warn "Missing rails rspec file #{file}" if !File.file?(file)
    end
  end
end