spec/reek/configuration/app_configuration_spec.rb in reek-3.4.1 vs spec/reek/configuration/app_configuration_spec.rb in reek-3.5.0

- old
+ new

@@ -36,11 +36,35 @@ expect(config.send(:directory_directives)).to eq(expected_directory_directives) end end describe '#from_map' do - it 'properly sets the configuration' do + let(:default_directive_value) do + { 'IrresponsibleModule' => { 'enabled' => false } } + end + + let(:directory_directives_value) do + { 'spec/samples/three_clean_files' => + { 'UtilityFunction' => { 'enabled' => false } } } + end + + let(:exclude_paths_value) do + ['spec/samples/two_smelly_files', + 'spec/samples/source_with_non_ruby_files'] + end + + it 'properly sets the configuration from simple data structures' do + config = described_class.from_map(directory_directives: directory_directives_value, + default_directive: default_directive_value, + excluded_paths: exclude_paths_value) + + expect(config.send(:excluded_paths)).to eq(expected_excluded_paths) + expect(config.send(:default_directive)).to eq(expected_default_directive) + expect(config.send(:directory_directives)).to eq(expected_directory_directives) + end + + it 'properly sets the configuration from native structures' do config = described_class.from_map(directory_directives: expected_directory_directives, default_directive: expected_default_directive, excluded_paths: expected_excluded_paths) expect(config.send(:excluded_paths)).to eq(expected_excluded_paths) @@ -49,44 +73,39 @@ end end end describe '#directive_for' do + let(:source_via) { 'spec/samples/three_clean_files/dummy.rb' } + context 'our source is in a directory for which we have a directive' do let(:baz_config) { { Reek::Smells::IrresponsibleModule => { enabled: false } } } let(:bang_config) { { Reek::Smells::Attribute => { enabled: true } } } let(:directory_directives) do { - Pathname.new('foo/bar/baz') => baz_config, - Pathname.new('foo/bar/bang') => bang_config + 'spec/samples/two_smelly_files' => baz_config, + 'spec/samples/three_clean_files' => bang_config } end - let(:source_via) { 'foo/bar/bang/dummy.rb' } it 'returns the corresponding directive' do configuration = described_class.from_map directory_directives: directory_directives expect(configuration.directive_for(source_via)).to eq(bang_config) end end context 'our source is not in a directory for which we have a directive' do - let(:irresponsible_module_config) do - { Reek::Smells::IrresponsibleModule => { enabled: false } } - end + let(:default_directive) { { Reek::Smells::IrresponsibleModule => { enabled: false } } } let(:attribute_config) { { Reek::Smells::Attribute => { enabled: false } } } - let(:default_directive) do - irresponsible_module_config - end let(:directory_directives) do - { Pathname.new('foo/bar/baz') => attribute_config } + { 'spec/samples/two_smelly_files' => attribute_config } end - let(:source_via) { 'foo/bar/bang/dummy.rb' } it 'returns the default directive' do configuration = described_class.from_map directory_directives: directory_directives, default_directive: default_directive - expect(configuration.directive_for(source_via)).to eq(irresponsible_module_config) + expect(configuration.directive_for(source_via)).to eq(default_directive) end end end end