aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/cask/cli/edit_spec.rb
diff options
context:
space:
mode:
authorMarkus Reiter2017-05-19 22:01:50 +0200
committerMarkus Reiter2017-05-22 02:51:16 +0200
commit276adc9e8b0071e6c61160b93e7bd399fe4f29e4 (patch)
tree896f9f68e0e45756f1722f51a1bad477f5ada815 /Library/Homebrew/test/cask/cli/edit_spec.rb
parent8248345a9a735aa9ee0421413166e9733bff277d (diff)
downloadbrew-276adc9e8b0071e6c61160b93e7bd399fe4f29e4.tar.bz2
Refactor `CLI::Edit`.
Diffstat (limited to 'Library/Homebrew/test/cask/cli/edit_spec.rb')
-rw-r--r--Library/Homebrew/test/cask/cli/edit_spec.rb41
1 files changed, 10 insertions, 31 deletions
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