Sha256: 613f9fd7473ab4001600bfca3b6aecd0da5709286626823f94adec89ceb742db

Contents?: true

Size: 1.1 KB

Versions: 52

Compression:

Stored size: 1.1 KB

Contents

require_relative 'concerns/deputisable'

module NdrDevSupport
  module RakeCI
    module CommitCop
      # This cop checks for new controllers, helpers,
      # mailers and models without a new, associated test file
      class MissingAssociatedTestFile
        include Deputisable

        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
      end
    end
  end
end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
ndr_dev_support-6.1.0 lib/ndr_dev_support/rake_ci/commit_cop/missing_associated_test_file.rb
ndr_dev_support-6.0.4 lib/ndr_dev_support/rake_ci/commit_cop/missing_associated_test_file.rb
ndr_dev_support-6.0.3 lib/ndr_dev_support/rake_ci/commit_cop/missing_associated_test_file.rb
ndr_dev_support-6.0.2 lib/ndr_dev_support/rake_ci/commit_cop/missing_associated_test_file.rb
ndr_dev_support-6.0.1 lib/ndr_dev_support/rake_ci/commit_cop/missing_associated_test_file.rb
ndr_dev_support-6.0.0 lib/ndr_dev_support/rake_ci/commit_cop/missing_associated_test_file.rb
ndr_dev_support-5.10.2 lib/ndr_dev_support/rake_ci/commit_cop/missing_associated_test_file.rb
ndr_dev_support-5.10.1 lib/ndr_dev_support/rake_ci/commit_cop/missing_associated_test_file.rb
ndr_dev_support-5.10.0 lib/ndr_dev_support/rake_ci/commit_cop/missing_associated_test_file.rb
ndr_dev_support-5.9.0 lib/ndr_dev_support/rake_ci/commit_cop/missing_associated_test_file.rb
ndr_dev_support-5.8.2 lib/ndr_dev_support/rake_ci/commit_cop/missing_associated_test_file.rb
ndr_dev_support-5.8.1 lib/ndr_dev_support/rake_ci/commit_cop/missing_associated_test_file.rb
ndr_dev_support-5.8.0 lib/ndr_dev_support/rake_ci/commit_cop/missing_associated_test_file.rb
ndr_dev_support-5.7.1 lib/ndr_dev_support/rake_ci/commit_cop/missing_associated_test_file.rb
ndr_dev_support-5.7.0 lib/ndr_dev_support/rake_ci/commit_cop/missing_associated_test_file.rb
ndr_dev_support-5.6.0 lib/ndr_dev_support/rake_ci/commit_cop/missing_associated_test_file.rb
ndr_dev_support-5.5.0 lib/ndr_dev_support/rake_ci/commit_cop/missing_associated_test_file.rb
ndr_dev_support-5.4.8 lib/ndr_dev_support/rake_ci/commit_cop/missing_associated_test_file.rb
ndr_dev_support-5.4.7 lib/ndr_dev_support/rake_ci/commit_cop/missing_associated_test_file.rb
ndr_dev_support-5.4.6 lib/ndr_dev_support/rake_ci/commit_cop/missing_associated_test_file.rb