diff options
| author | Markus Reiter | 2017-02-08 12:05:42 +0100 |
|---|---|---|
| committer | Markus Reiter | 2017-02-10 17:19:19 +0100 |
| commit | dcb206dd1ef1be09f75774c0f86692ad3e31c679 (patch) | |
| tree | ad3c16267f82d37a068a9a5f504b851ee26a3e91 /Library/Homebrew/cask/spec | |
| parent | 2ade29a5cf5df84ed9fb7dcf429c59c3e084a6a1 (diff) | |
| download | brew-dcb206dd1ef1be09f75774c0f86692ad3e31c679.tar.bz2 | |
Convert Create test to spec.
Diffstat (limited to 'Library/Homebrew/cask/spec')
| -rw-r--r-- | Library/Homebrew/cask/spec/cask/cli/create_spec.rb | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/Library/Homebrew/cask/spec/cask/cli/create_spec.rb b/Library/Homebrew/cask/spec/cask/cli/create_spec.rb new file mode 100644 index 000000000..e3d484d87 --- /dev/null +++ b/Library/Homebrew/cask/spec/cask/cli/create_spec.rb @@ -0,0 +1,100 @@ +require "spec_helper" + +# monkeypatch for testing +module Hbc + class CLI + class Create + 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::Create do + before(:each) do + Hbc::CLI::Create.reset! + end + + after(:each) do + %w[new-cask additional-cask another-cask yet-another-cask local-caff].each do |cask| + path = Hbc.path(cask) + path.delete if path.exist? + end + end + + it "opens the editor for the specified Cask" do + Hbc::CLI::Create.run("new-cask") + expect(Hbc::CLI::Create.editor_commands).to eq [ + [Hbc.path("new-cask")], + ] + end + + it "drops a template down for the specified Cask" do + Hbc::CLI::Create.run("new-cask") + template = File.read(Hbc.path("new-cask")) + expect(template).to eq <<-EOS.undent + cask 'new-cask' do + version '' + sha256 '' + + url 'https://' + name '' + homepage '' + + app '' + end + EOS + end + + it "throws away additional Cask arguments and uses the first" do + Hbc::CLI::Create.run("additional-cask", "another-cask") + expect(Hbc::CLI::Create.editor_commands).to eq [ + [Hbc.path("additional-cask")], + ] + end + + it "throws away stray options" do + Hbc::CLI::Create.run("--notavalidoption", "yet-another-cask") + expect(Hbc::CLI::Create.editor_commands).to eq [ + [Hbc.path("yet-another-cask")], + ] + end + + it "raises an exception when the Cask already exists" do + expect { + Hbc::CLI::Create.run("basic-cask") + }.to raise_error(Hbc::CaskAlreadyCreatedError) + end + + it "allows creating Casks that are substrings of existing Casks" do + Hbc::CLI::Create.run("local-caff") + expect(Hbc::CLI::Create.editor_commands).to eq [ + [Hbc.path("local-caff")], + ] + end + + describe "when no Cask is specified" do + it "raises an exception" do + expect { + Hbc::CLI::Create.run + }.to raise_error(Hbc::CaskUnspecifiedError) + end + end + + describe "when no Cask is specified, but an invalid option" do + it "raises an exception" do + expect { + Hbc::CLI::Create.run("--notavalidoption") + }.to raise_error(Hbc::CaskUnspecifiedError) + end + end +end |
