class NdrDevSupport::RakeCI::CommitCop::MissingAssociatedTestFile
This cop checks for new controllers, helpers, mailers and models without a new, associated test file
Public Instance Methods
check(changes)
click to toggle source
# File lib/ndr_dev_support/rake_ci/commit_cop/missing_associated_test_file.rb, line 11 def check(changes) added = changes[:added] return unless added.any? tested_paths = CommitCop.tested_paths.join('|') monitored_files = added.select { |file| file =~ %r{((#{tested_paths})\/.*\.rb)} } files_without_tests = monitored_files.reduce([]) do |missing_tests, monitored_file| test_file = monitored_file.gsub(%r{\A\w+\/(.*)\.rb\z}, 'test/\1_test.rb') added.include?(test_file) ? missing_tests : missing_tests << monitored_file end return if files_without_tests.empty? attachment :danger, 'No associated test file committed', "File(s) submitted without an associated test file:\n" \ "#{files_without_tests.join("\n")}" end