summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaire McQuin <mcquin@users.noreply.github.com>2014-08-07 10:59:22 -0700
committerSerdar Sutay <serdar@opscode.com>2014-08-15 14:53:10 -0700
commit8008b6cf07dd2fe9ae1ff83a144af5c3cc0582cd (patch)
tree29a35f47c148128cf9902450eec869bb8058147e
parent9f89e3c5ff2772d1e6d53db9b6c957a1e1d48730 (diff)
downloadchef-8008b6cf07dd2fe9ae1ff83a144af5c3cc0582cd.tar.gz
Merge pull request #1742 from CloCkWeRX/fix_duplicate_regex
Fix duplicate check regex
-rw-r--r--lib/chef/role.rb4
-rw-r--r--spec/unit/role_spec.rb6
2 files changed, 8 insertions, 2 deletions
diff --git a/lib/chef/role.rb b/lib/chef/role.rb
index 64952c6ab2..57f3a2aa29 100644
--- a/lib/chef/role.rb
+++ b/lib/chef/role.rb
@@ -236,8 +236,8 @@ class Chef
paths = Array(Chef::Config[:role_path])
paths.each do |path|
roles_files = Dir.glob(File.join(path, "**", "**"))
- js_files = roles_files.select { |file| file.match /#{name}\.json$/ }
- rb_files = roles_files.select { |file| file.match /#{name}\.rb$/ }
+ js_files = roles_files.select { |file| file.match /\/#{name}\.json$/ }
+ rb_files = roles_files.select { |file| file.match /\/#{name}\.rb$/ }
if js_files.count > 1 or rb_files.count > 1
raise Chef::Exceptions::DuplicateRole, "Multiple roles of same type found named #{name}"
end
diff --git a/spec/unit/role_spec.rb b/spec/unit/role_spec.rb
index 9ff75566b4..05ebf282db 100644
--- a/spec/unit/role_spec.rb
+++ b/spec/unit/role_spec.rb
@@ -296,6 +296,12 @@ EOR
File.should_not_receive(:exists?)
lambda {@role.class.from_disk("lolcat")}.should raise_error(Chef::Exceptions::DuplicateRole)
end
+
+ it "should not raise an exception if two files exist with a similar name" do
+ Dir.should_receive(:glob).and_return(["#{Chef::Config[:role_path]}/memes/lolcat.rb", "#{Chef::Config[:role_path]}/super_lolcat.rb"])
+ File.should_not_receive(:exists?)
+ lambda {@role.class.from_disk("lolcat")}.should_not raise_error(Chef::Exceptions::DuplicateRole)
+ end
end
describe "when loading from disk and role_path is an array" do