Skip to content

Commit

Permalink
Raise a UserError if the name attribute isn't in metadata.rb.
Browse files Browse the repository at this point in the history
References test-kitchen#116
  • Loading branch information
fnichol authored and Thom May committed May 30, 2013
1 parent 8bed0ff commit 66e4013
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
6 changes: 3 additions & 3 deletions lib/kitchen/chef_data_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ def cp_cookbooks(tmpdir)

def cp_this_cookbook(tmpdir)
metadata_rb = File.join(kitchen_root, "metadata.rb")
cb_name = MetadataChopper.extract(metadata_rb).first

raise TestKitchen::Errors::MissingCookbookName.new(name) if cb_name.nil?
cb_name = MetadataChopper.extract(metadata_rb).first or raise(UserError,
"The metadata.rb does not define the 'name' key." +
" Please add: `name '<cookbook_name>'` to metadata.rb and try again")

cb_path = File.join(tmpdir, cb_name)
glob = Dir.glob("#{kitchen_root}/{metadata.rb,README.*," +
Expand Down
18 changes: 0 additions & 18 deletions lib/kitchen/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,6 @@ class ActionFailed < TransientFailure ; end
# Exception class capturing what caused an instance to die.
class InstanceFailure < TransientFailure ; end

# Exception class raised when a cookbook's metadata is missing the name
# attribute.
class MissingCookbookName < StandardError
def initialize(name)
@name = name
end

def to_s
[
"The metadata.rb does not define the 'name' key. Please add:",
"",
" name '#{@name}'",
"",
"to the metadata.rb for '#{@name}' and try again."
].join("\n")
end
end

def self.with_friendly_errors
yield
rescue Kitchen::InstanceFailure => e
Expand Down

0 comments on commit 66e4013

Please sign in to comment.