2016-08-18 22:11:42 +03:00
|
|
|
# monkeypatch for testing
|
2016-09-24 13:52:43 +02:00
|
|
|
module Hbc
|
|
|
|
class CLI
|
|
|
|
class Edit
|
|
|
|
def self.exec_editor(*command)
|
|
|
|
editor_commands << command
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def self.reset!
|
|
|
|
@editor_commands = []
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def self.editor_commands
|
|
|
|
@editor_commands ||= []
|
|
|
|
end
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-05 19:26:56 +01:00
|
|
|
describe Hbc::CLI::Edit, :cask do
|
2017-02-08 12:11:04 +01:00
|
|
|
before(:each) do
|
2016-08-18 22:11:42 +03:00
|
|
|
Hbc::CLI::Edit.reset!
|
|
|
|
end
|
|
|
|
|
|
|
|
it "opens the editor for the specified Cask" do
|
2017-02-08 12:11:04 +01:00
|
|
|
Hbc::CLI::Edit.run("local-caffeine")
|
|
|
|
expect(Hbc::CLI::Edit.editor_commands).to eq [
|
|
|
|
[Hbc.path("local-caffeine")],
|
2016-10-14 20:33:16 +02:00
|
|
|
]
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
it "throws away additional arguments and uses the first" do
|
2017-02-08 12:11:04 +01:00
|
|
|
Hbc::CLI::Edit.run("local-caffeine", "local-transmission")
|
|
|
|
expect(Hbc::CLI::Edit.editor_commands).to eq [
|
|
|
|
[Hbc.path("local-caffeine")],
|
2016-10-14 20:33:16 +02:00
|
|
|
]
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
it "raises an exception when the Cask doesnt exist" do
|
2017-02-08 12:11:04 +01:00
|
|
|
expect {
|
2016-08-18 22:11:42 +03:00
|
|
|
Hbc::CLI::Edit.run("notacask")
|
2017-02-08 12:11:04 +01:00
|
|
|
}.to raise_error(Hbc::CaskUnavailableError)
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "when no Cask is specified" do
|
|
|
|
it "raises an exception" do
|
2017-02-08 12:11:04 +01:00
|
|
|
expect {
|
2016-08-18 22:11:42 +03:00
|
|
|
Hbc::CLI::Edit.run
|
2017-02-08 12:11:04 +01:00
|
|
|
}.to raise_error(Hbc::CaskUnspecifiedError)
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "when no Cask is specified, but an invalid option" do
|
|
|
|
it "raises an exception" do
|
2017-02-08 12:11:04 +01:00
|
|
|
expect {
|
2016-08-18 22:11:42 +03:00
|
|
|
Hbc::CLI::Edit.run("--notavalidoption")
|
2017-02-08 12:11:04 +01:00
|
|
|
}.to raise_error(Hbc::CaskUnspecifiedError)
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|