require 'spec_helper'

describe 'default configuration' do
  default_config =
    YAML.load_file(Overcommit::ConfigurationLoader::DEFAULT_CONFIG_PATH).to_hash

  Overcommit::Utils.supported_hook_type_classes.each do |hook_type|
    context "within the #{hook_type} configuration section" do
      default_config[hook_type].each do |hook_name, hook_config|
        next if hook_name == 'ALL'

        it "explicitly sets the `enabled` option for #{hook_name}" do
          # Use variable names so it reads nicer in the RSpec output
          hook_enabled_option_set = !hook_config['enabled'].nil?
          all_hook_enabled_option_set = !default_config[hook_type]['ALL']['enabled'].nil?

          (hook_enabled_option_set || all_hook_enabled_option_set).should == true
        end
      end
    end
  end
end

require 'spec_helper'

describe 'default configuration' do
  default_config =
    YAML.load_file(Overcommit::ConfigurationLoader::DEFAULT_CONFIG_PATH).to_hash

  Overcommit::Utils.supported_hook_types.each do |hook_type|
    hook_class = Overcommit::Utils.camel_case(hook_type)

    Dir[File.join(Overcommit::HOOK_DIRECTORY, hook_type.gsub('-', '_'), '*')].
      map { |hook_file| Overcommit::Utils.camel_case(File.basename(hook_file, '.rb')) }.
      each do |hook|
      next if hook == 'Base'

      context "for the #{hook} #{hook_type} hook" do
        it 'exists in config/default.yml' do
          default_config[hook_class][hook].should_not be_nil
        end

        it 'explicitly sets the enabled option' do
          # Use variable names so it reads nicer in the RSpec output
          hook_enabled_option_set = !default_config[hook_class][hook]['enabled'].nil?
          all_hook_enabled_option_set = !default_config[hook_class]['ALL']['enabled'].nil?

          (hook_enabled_option_set || all_hook_enabled_option_set).should == true
        end

        it 'defines a description' do
          default_config[hook_class][hook]['description'].should_not be_nil
        end
      end
    end
  end
end

Add tests verifying configuration for hooks
Add tests verifying configuration for hooks

Building on top of a5e834b, we want to also verify that all hooks have a
`description` specified, as well as a configuration in general. We
change the implementation to work backwards from the file names so that
if we create a hook file but forget to add a configuration for it we'll
get a test failure.
