Class: NdrDevSupport::RakeCI::CommitCop::MissingAssociatedTestFile
- Inherits:
-
Object
- Object
- NdrDevSupport::RakeCI::CommitCop::MissingAssociatedTestFile
- Includes:
- Deputisable
- Defined in:
- lib/ndr_dev_support/rake_ci/commit_cop/missing_associated_test_file.rb
Overview
This cop checks for new controllers, helpers, mailers and models without a new, associated test file
Instance Method Summary collapse
Instance Method Details
#check(changes) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# 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? :danger, 'No associated test file committed', "File(s) submitted without an associated test file:\n" \ "#{files_without_tests.join("\n")}" end |