Skip to content
This repository has been archived by the owner on May 22, 2018. It is now read-only.

Commit

Permalink
raise a real error if the command isn't registered or the name is nil
Browse files Browse the repository at this point in the history
  • Loading branch information
wfarr committed Mar 7, 2014
1 parent 57744b6 commit 4099565
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/boxen/command.rb
Expand Up @@ -5,6 +5,8 @@
require "boxen/postflight"

class Boxen::Command
class UnknownCommandError < StandardError; end

attr_reader :config

def self.help
Expand Down Expand Up @@ -47,11 +49,12 @@ def self.reset!
@commands = {}
end

def self.invoke(name, config, *args)
if @commands && @commands.has_key?(name.to_sym)
@commands[name.to_sym].new(config, *args).invoke
def self.invoke(name, *args)
if @commands && name && @commands.has_key?(name.to_sym)
@commands[name.to_sym].new(*args).invoke
else
raise "Could not find command #{name}!"
raise UnknownCommandError,
"could not find `#{name}` in the list of registered commands"
end
end

Expand Down
12 changes: 12 additions & 0 deletions test/boxen_command_test.rb
Expand Up @@ -47,6 +47,18 @@ def @config.debug?; false; end
assert_match "foo", stdout
end

it "fails with UnknownCommandError if the invoked command is not registered" do
assert_raises Boxen::Command::UnknownCommandError do
Boxen::Command.invoke :random_command
end
end

it "fails with UnknownCommandError if the invoked command is nil" do
assert_raises Boxen::Command::UnknownCommandError do
Boxen::Command.invoke nil
end
end

it "executes preflight hooks" do
Boxen::Command.register :barnette, Boxen::Command::Barnette

Expand Down

0 comments on commit 4099565

Please sign in to comment.