Skip to content

Commit

Permalink
prefix abort messages with executable name to have more explicit errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cldwalker committed Mar 18, 2012
1 parent 24dd618 commit e879210
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions lib/boson/runner.rb
Expand Up @@ -56,6 +56,10 @@ def self.app_name
File.basename($0).split(' ').first
end

def self.abort_with(msg)
super "#{app_name}: #{msg}"
end

private
def self.load_options
{force: true}
Expand Down
10 changes: 5 additions & 5 deletions test/runner_test.rb
Expand Up @@ -122,7 +122,7 @@ def default_usage

it 'prints error for invalid command' do
Boson::DefaultCommandsRunner.expects(:abort).
with("Could not find command \"invalid\"")
with("my_command: Could not find command \"invalid\"")
my_command('help invalid')
end
end
Expand Down Expand Up @@ -186,7 +186,7 @@ def default_usage

it "calls command with too many args" do
MyRunner.expects(:abort).with <<-STR.chomp
'medium' was called incorrectly.
my_command: 'medium' was called incorrectly.
Usage: medium [ARG]
STR
my_command('medium 1 2 3')
Expand All @@ -213,12 +213,12 @@ def default_usage
end

it "prints error message for internal public method" do
MyRunner.expects(:abort).with %[Could not find command "to_s"]
MyRunner.expects(:abort).with %[my_command: Could not find command "to_s"]
my_command('to_s').should == ''
end

it "prints error message for nonexistant command" do
MyRunner.expects(:abort).with %[Could not find command "blarg"]
MyRunner.expects(:abort).with %[my_command: Could not find command "blarg"]
my_command('blarg').should == ''
end

Expand All @@ -231,7 +231,7 @@ def default_usage
end

it "prints error message for private method" do
MyRunner.expects(:abort).with %[Could not find command "no_run"]
MyRunner.expects(:abort).with %[my_command: Could not find command "no_run"]
my_command('no_run').should == ''
end

Expand Down

0 comments on commit e879210

Please sign in to comment.