From c0210de9c881a9b52c4ca28aef5cfc0a447dbd2a Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sat, 18 Jan 2014 11:54:10 -0500 Subject: [PATCH] Show usage in plugins:install/uninstall commands when an argument is not provided Right now a TypeError (no implicit conversion of nil into String) is raised --- lib/heroku/command/plugins.rb | 10 +++- spec/heroku/command/plugins_spec.rb | 86 ++++++++++++++++++++--------- 2 files changed, 67 insertions(+), 29 deletions(-) diff --git a/lib/heroku/command/plugins.rb b/lib/heroku/command/plugins.rb index 086f68113..7471b0120 100644 --- a/lib/heroku/command/plugins.rb +++ b/lib/heroku/command/plugins.rb @@ -38,7 +38,10 @@ def index # Installing heroku-accounts... done # def install - plugin = Heroku::Plugin.new(shift_argument) + unless plugin_url = shift_argument + error("Usage: heroku plugins:install URL") + end + plugin = Heroku::Plugin.new(plugin_url) validate_arguments! action("Installing #{plugin.name}") do @@ -63,7 +66,10 @@ def install # Uninstalling heroku-accounts... done # def uninstall - plugin = Heroku::Plugin.new(shift_argument) + unless plugin_name = shift_argument + error("Usage: heroku plugins:uninstall PLUGIN") + end + plugin = Heroku::Plugin.new(plugin_name) validate_arguments! action("Uninstalling #{plugin.name}") do diff --git a/spec/heroku/command/plugins_spec.rb b/spec/heroku/command/plugins_spec.rb index 272c06ccd..31a3006a6 100644 --- a/spec/heroku/command/plugins_spec.rb +++ b/spec/heroku/command/plugins_spec.rb @@ -12,53 +12,85 @@ module Heroku::Command context("install") do - before do - Heroku::Plugin.should_receive(:new).with('git://github.com/heroku/Plugin.git').and_return(@plugin) - @plugin.should_receive(:install).and_return(true) + context("when a plugin URL is not specified") do + + it "requires a URL to be specified" do + stderr, stdout = execute("plugins:install") + stderr.should == <<-STDERR + ! Usage: heroku plugins:install URL +STDERR + stdout.should == "" + end + end - it "installs plugins" do - Heroku::Plugin.should_receive(:load_plugin).and_return(true) - stderr, stdout = execute("plugins:install git://github.com/heroku/Plugin.git") - stderr.should == "" - stdout.should == <<-STDOUT + context("when a plugin URL is specified") do + + before do + Heroku::Plugin.should_receive(:new).with('git://github.com/heroku/Plugin.git').and_return(@plugin) + @plugin.should_receive(:install).and_return(true) + end + + it "installs plugins" do + Heroku::Plugin.should_receive(:load_plugin).and_return(true) + stderr, stdout = execute("plugins:install git://github.com/heroku/Plugin.git") + stderr.should == "" + stdout.should == <<-STDOUT Installing Plugin... done STDOUT - end + end + + it "does not install plugins that do not load" do + Heroku::Plugin.should_receive(:load_plugin).and_return(false) + @plugin.should_receive(:uninstall).and_return(true) + stderr, stdout = execute("plugins:install git://github.com/heroku/Plugin.git") + stderr.should == '' # normally would have error, but mocks/stubs don't allow + stdout.should == "Installing Plugin... " # also inaccurate, would end in ' failed' + end - it "does not install plugins that do not load" do - Heroku::Plugin.should_receive(:load_plugin).and_return(false) - @plugin.should_receive(:uninstall).and_return(true) - stderr, stdout = execute("plugins:install git://github.com/heroku/Plugin.git") - stderr.should == '' # normally would have error, but mocks/stubs don't allow - stdout.should == "Installing Plugin... " # also inaccurate, would end in ' failed' end end context("uninstall") do - before do - Heroku::Plugin.should_receive(:new).with('Plugin').and_return(@plugin) + context("when a plugin is not specified") do + + it "requires a name to be specified" do + stderr, stdout = execute("plugins:uninstall") + stderr.should == <<-STDERR + ! Usage: heroku plugins:uninstall PLUGIN +STDERR + stdout.should == "" + end + end - it "uninstalls plugins" do - @plugin.should_receive(:uninstall).and_return(true) - stderr, stdout = execute("plugins:uninstall Plugin") - stderr.should == "" - stdout.should == <<-STDOUT + context("when a plugin is specified") do + + before do + Heroku::Plugin.should_receive(:new).with('Plugin').and_return(@plugin) + end + + it "uninstalls plugins" do + @plugin.should_receive(:uninstall).and_return(true) + stderr, stdout = execute("plugins:uninstall Plugin") + stderr.should == "" + stdout.should == <<-STDOUT Uninstalling Plugin... done STDOUT - end + end - it "does not uninstall plugins that do not exist" do - stderr, stdout = execute("plugins:uninstall Plugin") - stderr.should == <<-STDERR + it "does not uninstall plugins that do not exist" do + stderr, stdout = execute("plugins:uninstall Plugin") + stderr.should == <<-STDERR ! Plugin plugin not found. STDERR - stdout.should == <<-STDOUT + stdout.should == <<-STDOUT Uninstalling Plugin... failed STDOUT + end + end end