Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Show usage in plugins:install/uninstall commands when an argument is not provided #1005

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/heroku/command/plugins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
86 changes: 59 additions & 27 deletions spec/heroku/command/plugins_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down