Skip to content
This repository
Browse code

Should be checking if file exists or not.

I found this bug when running rake test:uncommitted 
on a newly generated rails app which don't have
test file for application_controller.
Can see detail here #3461
  • Loading branch information...
commit fe67501e62429a8d9c666837740cf9c1de1d4f87 1 parent 588faed
Arun Agrawal arunagw authored

Showing 1 changed file with 9 additions and 3 deletions. Show diff stats Hide diff stats

  1. +9 3 railties/lib/rails/test_unit/testing.rake
12 railties/lib/rails/test_unit/testing.rake
@@ -121,10 +121,16 @@ namespace :test do
121 121 models = changed_since_checkin.select { |path| path =~ /app[\\\/]models[\\\/].*\.rb$/ }
122 122 controllers = changed_since_checkin.select { |path| path =~ /app[\\\/]controllers[\\\/].*\.rb$/ }
123 123
124   - unit_tests = models.map { |model| "test/unit/#{File.basename(model, '.rb')}_test.rb" }
125   - functional_tests = controllers.map { |controller| "test/functional/#{File.basename(controller, '.rb')}_test.rb" }
  124 + unit_tests = models.map do |model|
  125 + file = "test/unit/#{File.basename(model, '.rb')}_test.rb"
  126 + file if File.exist?(file)
  127 + end
  128 + functional_tests = controllers.map do |controller|
  129 + file = "test/functional/#{File.basename(controller, '.rb')}_test.rb"
  130 + file if File.exist?(file)
  131 + end
126 132
127   - unit_tests.uniq + functional_tests.uniq
  133 + (unit_tests.uniq + functional_tests.uniq).compact
128 134 end
129 135
130 136 t.libs << 'test'

1 comment on commit fe67501

Gabriel Sobrinho

Could reduce duplication :)

(unit_test + functional_tests).uniq.select do |file|
  File.exist?(file)
end
Please sign in to comment.
Something went wrong with that request. Please try again.