From dcb206dd1ef1be09f75774c0f86692ad3e31c679 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 8 Feb 2017 12:05:42 +0100 Subject: Convert Create test to spec. --- Library/Homebrew/cask/spec/cask/cli/create_spec.rb | 100 +++++++++++++++++++++ Library/Homebrew/cask/test/cask/cli/create_test.rb | 100 --------------------- 2 files changed, 100 insertions(+), 100 deletions(-) create mode 100644 Library/Homebrew/cask/spec/cask/cli/create_spec.rb delete mode 100644 Library/Homebrew/cask/test/cask/cli/create_test.rb (limited to 'Library') 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 diff --git a/Library/Homebrew/cask/test/cask/cli/create_test.rb b/Library/Homebrew/cask/test/cask/cli/create_test.rb deleted file mode 100644 index f09c91e8e..000000000 --- a/Library/Homebrew/cask/test/cask/cli/create_test.rb +++ /dev/null @@ -1,100 +0,0 @@ -require "test_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 do - Hbc::CLI::Create.reset! - end - - after 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") - Hbc::CLI::Create.editor_commands.must_equal [ - [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")) - template.must_equal <<-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") - Hbc::CLI::Create.editor_commands.must_equal [ - [Hbc.path("additional-cask")], - ] - end - - it "throws away stray options" do - Hbc::CLI::Create.run("--notavalidoption", "yet-another-cask") - Hbc::CLI::Create.editor_commands.must_equal [ - [Hbc.path("yet-another-cask")], - ] - end - - it "raises an exception when the Cask already exists" do - lambda { - Hbc::CLI::Create.run("basic-cask") - }.must_raise Hbc::CaskAlreadyCreatedError - end - - it "allows creating Casks that are substrings of existing Casks" do - Hbc::CLI::Create.run("local-caff") - Hbc::CLI::Create.editor_commands.must_equal [ - [Hbc.path("local-caff")], - ] - end - - describe "when no Cask is specified" do - it "raises an exception" do - lambda { - Hbc::CLI::Create.run - }.must_raise Hbc::CaskUnspecifiedError - end - end - - describe "when no Cask is specified, but an invalid option" do - it "raises an exception" do - lambda { - Hbc::CLI::Create.run("--notavalidoption") - }.must_raise Hbc::CaskUnspecifiedError - end - end -end -- cgit v1.2.3