Convert Create test to spec.

This commit is contained in:
Markus Reiter 2017-02-08 12:05:42 +01:00
parent 2ade29a5cf
commit dcb206dd1e

View File

@ -1,4 +1,4 @@
require "test_helper" require "spec_helper"
# monkeypatch for testing # monkeypatch for testing
module Hbc module Hbc
@ -20,11 +20,11 @@ module Hbc
end end
describe Hbc::CLI::Create do describe Hbc::CLI::Create do
before do before(:each) do
Hbc::CLI::Create.reset! Hbc::CLI::Create.reset!
end end
after do after(:each) do
%w[new-cask additional-cask another-cask yet-another-cask local-caff].each do |cask| %w[new-cask additional-cask another-cask yet-another-cask local-caff].each do |cask|
path = Hbc.path(cask) path = Hbc.path(cask)
path.delete if path.exist? path.delete if path.exist?
@ -33,7 +33,7 @@ describe Hbc::CLI::Create do
it "opens the editor for the specified Cask" do it "opens the editor for the specified Cask" do
Hbc::CLI::Create.run("new-cask") Hbc::CLI::Create.run("new-cask")
Hbc::CLI::Create.editor_commands.must_equal [ expect(Hbc::CLI::Create.editor_commands).to eq [
[Hbc.path("new-cask")], [Hbc.path("new-cask")],
] ]
end end
@ -41,7 +41,7 @@ describe Hbc::CLI::Create do
it "drops a template down for the specified Cask" do it "drops a template down for the specified Cask" do
Hbc::CLI::Create.run("new-cask") Hbc::CLI::Create.run("new-cask")
template = File.read(Hbc.path("new-cask")) template = File.read(Hbc.path("new-cask"))
template.must_equal <<-EOS.undent expect(template).to eq <<-EOS.undent
cask 'new-cask' do cask 'new-cask' do
version '' version ''
sha256 '' sha256 ''
@ -57,44 +57,44 @@ describe Hbc::CLI::Create do
it "throws away additional Cask arguments and uses the first" do it "throws away additional Cask arguments and uses the first" do
Hbc::CLI::Create.run("additional-cask", "another-cask") Hbc::CLI::Create.run("additional-cask", "another-cask")
Hbc::CLI::Create.editor_commands.must_equal [ expect(Hbc::CLI::Create.editor_commands).to eq [
[Hbc.path("additional-cask")], [Hbc.path("additional-cask")],
] ]
end end
it "throws away stray options" do it "throws away stray options" do
Hbc::CLI::Create.run("--notavalidoption", "yet-another-cask") Hbc::CLI::Create.run("--notavalidoption", "yet-another-cask")
Hbc::CLI::Create.editor_commands.must_equal [ expect(Hbc::CLI::Create.editor_commands).to eq [
[Hbc.path("yet-another-cask")], [Hbc.path("yet-another-cask")],
] ]
end end
it "raises an exception when the Cask already exists" do it "raises an exception when the Cask already exists" do
lambda { expect {
Hbc::CLI::Create.run("basic-cask") Hbc::CLI::Create.run("basic-cask")
}.must_raise Hbc::CaskAlreadyCreatedError }.to raise_error(Hbc::CaskAlreadyCreatedError)
end end
it "allows creating Casks that are substrings of existing Casks" do it "allows creating Casks that are substrings of existing Casks" do
Hbc::CLI::Create.run("local-caff") Hbc::CLI::Create.run("local-caff")
Hbc::CLI::Create.editor_commands.must_equal [ expect(Hbc::CLI::Create.editor_commands).to eq [
[Hbc.path("local-caff")], [Hbc.path("local-caff")],
] ]
end end
describe "when no Cask is specified" do describe "when no Cask is specified" do
it "raises an exception" do it "raises an exception" do
lambda { expect {
Hbc::CLI::Create.run Hbc::CLI::Create.run
}.must_raise Hbc::CaskUnspecifiedError }.to raise_error(Hbc::CaskUnspecifiedError)
end end
end end
describe "when no Cask is specified, but an invalid option" do describe "when no Cask is specified, but an invalid option" do
it "raises an exception" do it "raises an exception" do
lambda { expect {
Hbc::CLI::Create.run("--notavalidoption") Hbc::CLI::Create.run("--notavalidoption")
}.must_raise Hbc::CaskUnspecifiedError }.to raise_error(Hbc::CaskUnspecifiedError)
end end
end end
end end