diff --git a/lib/autotest/rails.rb b/lib/autotest/rails.rb index 3dda8a0..1e25783 100644 --- a/lib/autotest/rails.rb +++ b/lib/autotest/rails.rb @@ -80,7 +80,7 @@ def path_to_classname(s) sep = File::SEPARATOR parts = s.sub(/^test#{sep}((#{ignored_namespaces})#{sep})?/, '').sub(/\.rb$/, '').split(sep) modules = parts.map { |path| path.split(/_/).map { |seg| seg.capitalize }.join } - modules = modules.map { |path| path =~ /Test$/ ? path : "#{path}Test" } + modules[-1] = "#{modules.last}Test" unless modules.last =~ /Test$/ modules.join('::') end end diff --git a/test/rails_test.rb b/test/rails_test.rb index a9ef590..c603013 100644 --- a/test/rails_test.rb +++ b/test/rails_test.rb @@ -15,11 +15,15 @@ class RailsTest < MiniTest::Unit::TestCase end it "should convert non-default namespaces" do - assert_equal "FooTest::PostControllerTest", @at.path_to_classname("test/foo/post_controller_test.rb") + assert_equal "Foo::PostControllerTest", @at.path_to_classname("test/foo/post_controller_test.rb") end it "should convert normal namespaces inside ignored namespaces" do - assert_equal "BloggingTest::PostControllerTest", @at.path_to_classname("test/controllers/blogging/post_controller_test.rb") + assert_equal "Blogging::PostControllerTest", @at.path_to_classname("test/controllers/blogging/post_controller_test.rb") + end + + it "does not remove _test namespces" do + assert_equal "BloggingTest::PostControllerTest", @at.path_to_classname("test/controllers/blogging_test/post_controller_test.rb") end end end