From be9415a4a1ee4892a6869158c03551cb078bd0a7 Mon Sep 17 00:00:00 2001 From: Kevin Formsma Date: Mon, 12 Apr 2021 11:04:58 -0400 Subject: [PATCH] Use full path when loading file rules (#525) Resolves #520 --- .../rule_repos/file_based_rule_repo.rb | 2 +- spec/rules_repos/file_base_rule_repo_spec.rb | 107 ++++++++++++------ 2 files changed, 71 insertions(+), 38 deletions(-) diff --git a/lib/cfn-nag/rule_repos/file_based_rule_repo.rb b/lib/cfn-nag/rule_repos/file_based_rule_repo.rb index 52bbecc8..1f704668 100644 --- a/lib/cfn-nag/rule_repos/file_based_rule_repo.rb +++ b/lib/cfn-nag/rule_repos/file_based_rule_repo.rb @@ -52,7 +52,7 @@ def discover_rule_classes(rule_directory) rule_filenames = discover_rule_filenames(rule_directory) rule_filenames.each do |rule_filename| - require(rule_filename) + require(File.absolute_path(rule_filename)) rule_classname = File.basename(rule_filename, '.rb') rule_classes << Object.const_get(rule_classname) diff --git a/spec/rules_repos/file_base_rule_repo_spec.rb b/spec/rules_repos/file_base_rule_repo_spec.rb index 25e1e942..38d28e02 100644 --- a/spec/rules_repos/file_base_rule_repo_spec.rb +++ b/spec/rules_repos/file_base_rule_repo_spec.rb @@ -6,52 +6,85 @@ describe FileBasedRuleRepo do describe '#discover_rules' do context 'external rule directory' do - before(:each) do - fake_rule = <