diff options
| author | Markus Reiter | 2017-05-19 22:01:50 +0200 |
|---|---|---|
| committer | Markus Reiter | 2017-05-22 02:51:16 +0200 |
| commit | 276adc9e8b0071e6c61160b93e7bd399fe4f29e4 (patch) | |
| tree | 896f9f68e0e45756f1722f51a1bad477f5ada815 /Library | |
| parent | 8248345a9a735aa9ee0421413166e9733bff277d (diff) | |
| download | brew-276adc9e8b0071e6c61160b93e7bd399fe4f29e4.tar.bz2 | |
Refactor `CLI::Edit`.
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli/edit.rb | 6 | ||||
| -rw-r--r-- | Library/Homebrew/test/cask/cli/edit_spec.rb | 41 |
2 files changed, 15 insertions, 32 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/cli/edit.rb b/Library/Homebrew/cask/lib/hbc/cli/edit.rb index 1f1e0d918..52b089a8b 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/edit.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/edit.rb @@ -2,7 +2,11 @@ module Hbc class CLI class Edit < Base def self.run(*args) - cask_tokens = cask_tokens_from(args) + new(*args).run + end + + def run + cask_tokens = self.class.cask_tokens_from(@args) raise CaskUnspecifiedError if cask_tokens.empty? # only respects the first argument cask_token = cask_tokens.first.sub(/\.rb$/i, "") diff --git a/Library/Homebrew/test/cask/cli/edit_spec.rb b/Library/Homebrew/test/cask/cli/edit_spec.rb index f5f98afc8..a097f0894 100644 --- a/Library/Homebrew/test/cask/cli/edit_spec.rb +++ b/Library/Homebrew/test/cask/cli/edit_spec.rb @@ -1,51 +1,30 @@ -# monkeypatch for testing -module Hbc - class CLI - class Edit - def self.exec_editor(*command) - editor_commands << command - end - - def self.reset! - @editor_commands = [] - end - - def self.editor_commands - @editor_commands ||= [] - end - end - end -end - describe Hbc::CLI::Edit, :cask do before(:each) do - Hbc::CLI::Edit.reset! + allow_any_instance_of(described_class).to receive(:exec_editor) end it "opens the editor for the specified Cask" do - Hbc::CLI::Edit.run("local-caffeine") - expect(Hbc::CLI::Edit.editor_commands).to eq [ - [Hbc::CaskLoader.path("local-caffeine")], - ] + command = described_class.new("local-caffeine") + expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("local-caffeine")) + command.run end it "throws away additional arguments and uses the first" do - Hbc::CLI::Edit.run("local-caffeine", "local-transmission") - expect(Hbc::CLI::Edit.editor_commands).to eq [ - [Hbc::CaskLoader.path("local-caffeine")], - ] + command = described_class.new("local-caffeine", "local-transmission") + expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("local-caffeine")) + command.run end it "raises an exception when the Cask doesnt exist" do expect { - Hbc::CLI::Edit.run("notacask") + described_class.run("notacask") }.to raise_error(Hbc::CaskUnavailableError) end describe "when no Cask is specified" do it "raises an exception" do expect { - Hbc::CLI::Edit.run + described_class.run }.to raise_error(Hbc::CaskUnspecifiedError) end end @@ -53,7 +32,7 @@ describe Hbc::CLI::Edit, :cask do describe "when no Cask is specified, but an invalid option" do it "raises an exception" do expect { - Hbc::CLI::Edit.run("--notavalidoption") + described_class.run("--notavalidoption") }.to raise_error(Hbc::CaskUnspecifiedError) end end |
