Skip to content

Commit

Permalink
fix lot of minor bugs and inconsistencies
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Nov 7, 2010
1 parent 81db79f commit ca72468
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 32 deletions.
2 changes: 2 additions & 0 deletions Readme.md
Expand Up @@ -3,6 +3,8 @@ Autotest for Test::Unit on Rails, including plugins for migrations and fixtures.
- independent of ZenTest
- added tests
- fixed namespace issues
- support application_controller.rb
- lib/foo/bar -> test/unit/foo/bar_test

Install
=======
Expand Down
76 changes: 45 additions & 31 deletions lib/autotest/rails.rb
Expand Up @@ -10,77 +10,91 @@ def initialize # :nodoc:

clear_mappings

self.add_mapping(/^lib\/.*\.rb$/) do |filename, _|
impl = File.basename(filename, '.rb')
files_matching %r%^test/unit/#{impl}_test.rb$%
# TODO: (unit|functional|integration) maybe?
# lib/foo/bar.rb -> unit/foo/bar_test.rb
add_mapping %r%^lib/(.*)\.rb$% do |_, m|
"test/unit/#{m[1]}_test.rb"
end

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

add_mapping %r%^test/(unit|integration|controllers|views|functional)/.*rb$% do |filename, _|
# test changes -> run test
add_mapping %r%^test/(#{test_namespaces*'|'})/.*rb$% do |filename, _|
filename
end

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

# application_helper -> all views/helpers/controllers
add_mapping %r%^app/helpers/application_helper.rb% do
files_matching %r%^test/(views|functional)/.*_test\.rb$%
files_matching %r%^test/(views|functional|helpers)/.*_test\.rb$%
end

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

# view -> view + controller
add_mapping %r%^app/views/(.*)/% do |_, m|
["test/views/#{m[1]}_view_test.rb",
"test/functional/#{m[1]}_controller_test.rb"]
[
"test/views/#{m[1]}_view_test.rb",
"test/functional/#{m[1]}_controller_test.rb",
"test/controllers/#{m[1]}_controller_test.rb"
]
end

# application_controller.rb -> all views/controllers
add_mapping %r%^app/controllers/application_controller\.rb$% do |_, m|
files_matching %r%^test/(controllers|views|functional)/.*_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
["test/controllers/#{m[1]}_test.rb",
"test/functional/#{m[1]}_test.rb"]
end
[
"test/controllers/#{m[1]}_test.rb",
"test/functional/#{m[1]}_test.rb"
]
end

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

add_mapping %r%^config/routes.rb$% do # FIX:
files_matching %r%^test/(controllers|views|functional)/.*_test\.rb$%
# routes -> views + controllers + integration
add_mapping %r%^config/routes.rb$% do
files_matching %r%^test/(controllers|views|functional|integration)/.*_test\.rb$%
end

# config -> everything
add_mapping %r%^test/test_helper.rb|config/((boot|environment(s/test)?).rb|database.yml)% do
files_matching %r%^test/(unit|controllers|views|functional)/.*_test\.rb$%
files_matching %r%^test/(#{test_namespaces*'|'})/.*_test\.rb$%
end
end

def ignored_namespaces
'unit|functional|integration|views|controllers|helpers|cells'
def test_namespaces
%w[unit functional integration views controllers helpers cells]
end

# Convert the pathname s to the name of class.
def path_to_classname(s)
sep = File::SEPARATOR
parts = s.sub(/^test#{sep}((#{ignored_namespaces})#{sep})?/, '').sub(/\.rb$/, '').split(sep)
parts = s.sub(/^test#{sep}((#{test_namespaces*'|'})#{sep})?/, '').sub(/\.rb$/, '').split(sep)
modules = parts.map { |path| path.split(/_/).map { |seg| seg.capitalize }.join }
modules[-1] = "#{modules.last}Test" unless modules.last =~ /Test$/
modules.join('::')
end
end
end
2 changes: 1 addition & 1 deletion test/rails_test.rb
Expand Up @@ -27,4 +27,4 @@ class RailsTest < MiniTest::Unit::TestCase
end
end
end
end
end

0 comments on commit ca72468

Please sign in to comment.