2012-10-14 04:24:45 +08:00
|
|
|
require 'test_helper'
|
2012-10-14 03:39:00 +08:00
|
|
|
|
2013-04-08 01:46:35 +08:00
|
|
|
describe "Cask" do
|
2012-10-14 03:39:00 +08:00
|
|
|
describe "load" do
|
|
|
|
it "returns an instance of the cask with the given name" do
|
|
|
|
c = Cask.load("adium")
|
|
|
|
c.must_be_kind_of(Cask)
|
|
|
|
c.must_be_instance_of(Adium)
|
|
|
|
end
|
2013-11-06 11:07:52 +08:00
|
|
|
|
2013-07-17 06:12:16 +08:00
|
|
|
it "returns an instance of the cask from a specific file location" do
|
2014-02-13 22:21:47 +08:00
|
|
|
# defensive constant cleanup is required because Cask
|
|
|
|
# classes may already be loaded due to audit test
|
|
|
|
begin
|
|
|
|
Object.class_eval{remove_const :Dia}
|
|
|
|
rescue
|
2014-02-04 19:05:21 +08:00
|
|
|
end
|
2013-07-18 01:10:03 +08:00
|
|
|
location = File.expand_path('./Casks/dia.rb')
|
|
|
|
c = Cask.load(location)
|
|
|
|
c.must_be_kind_of(Cask)
|
|
|
|
c.must_be_instance_of(Dia)
|
2014-02-13 22:21:47 +08:00
|
|
|
Object.class_eval{remove_const :Dia}
|
2013-07-18 01:10:03 +08:00
|
|
|
end
|
|
|
|
|
2013-07-27 02:54:40 +08:00
|
|
|
it "returns an instance of the cask from a url" do
|
2014-02-13 22:21:47 +08:00
|
|
|
begin
|
|
|
|
Object.class_eval{remove_const :Dia}
|
|
|
|
rescue
|
2014-02-04 19:05:21 +08:00
|
|
|
end
|
2013-07-28 06:08:51 +08:00
|
|
|
url = "file://" + File.expand_path('./Casks/dia.rb')
|
2014-01-05 02:16:16 +08:00
|
|
|
c = shutup do
|
|
|
|
Cask.load(url)
|
|
|
|
end
|
2013-07-27 02:54:40 +08:00
|
|
|
c.must_be_kind_of(Cask)
|
|
|
|
c.must_be_instance_of(Dia)
|
2014-02-13 22:21:47 +08:00
|
|
|
Object.class_eval{remove_const :Dia}
|
2013-07-27 02:54:40 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "raises an error when failing to download a cask from a url" do
|
|
|
|
lambda {
|
2013-07-31 05:07:11 +08:00
|
|
|
url = "file://" + File.expand_path('./Casks/notacask.rb')
|
2014-01-05 02:16:16 +08:00
|
|
|
shutup do
|
|
|
|
Cask.load(url)
|
|
|
|
end
|
2013-07-27 02:54:40 +08:00
|
|
|
}.must_raise(CaskUnavailableError)
|
|
|
|
end
|
|
|
|
|
2013-07-18 01:10:03 +08:00
|
|
|
it "returns an instance of the cask from a relative file location" do
|
2014-02-13 22:21:47 +08:00
|
|
|
begin
|
|
|
|
Object.class_eval{remove_const :Bbedit}
|
|
|
|
rescue
|
2014-02-04 19:05:21 +08:00
|
|
|
end
|
|
|
|
c = Cask.load("./Casks/bbedit.rb")
|
2013-07-17 06:12:16 +08:00
|
|
|
c.must_be_kind_of(Cask)
|
2014-02-04 19:05:21 +08:00
|
|
|
c.must_be_instance_of(Bbedit)
|
2014-02-13 22:21:47 +08:00
|
|
|
Object.class_eval{remove_const :Bbedit}
|
2013-07-17 06:12:16 +08:00
|
|
|
end
|
2012-10-14 03:39:00 +08:00
|
|
|
|
2013-11-06 11:07:52 +08:00
|
|
|
it "uses exact match when loading by name" do
|
2014-02-25 21:22:05 +08:00
|
|
|
Cask.load('test-opera').must_be_instance_of(TestOpera)
|
|
|
|
Cask.load('test-opera-mail').must_be_instance_of(TestOperaMail)
|
2013-11-06 11:07:52 +08:00
|
|
|
end
|
|
|
|
|
2012-10-14 03:39:00 +08:00
|
|
|
it "raises an error when attempting to load a cask that doesn't exist" do
|
|
|
|
lambda {
|
|
|
|
Cask.load("notacask")
|
|
|
|
}.must_raise(CaskUnavailableError)
|
|
|
|
end
|
|
|
|
end
|
2012-10-14 05:17:52 +08:00
|
|
|
|
2012-11-19 13:10:28 +08:00
|
|
|
describe "all_titles" do
|
2012-10-14 05:17:52 +08:00
|
|
|
it "returns every cask that there is as a string" do
|
2012-11-19 13:10:28 +08:00
|
|
|
all_casks = Cask.all_titles
|
2012-10-14 05:17:52 +08:00
|
|
|
all_casks.count.must_be :>, 20
|
|
|
|
all_casks.each { |cask| cask.must_be_kind_of String }
|
|
|
|
end
|
|
|
|
end
|
2012-12-18 07:59:58 +08:00
|
|
|
|
|
|
|
describe "title" do
|
|
|
|
it "converts class constant to dasherized string" do
|
|
|
|
PascalCasedConstant = Class.new(Cask)
|
|
|
|
PascalCasedConstant.title.must_equal 'pascal-cased-constant'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "properly dasherizes constants with single letters in the middle" do
|
|
|
|
GamesXChange = Class.new(Cask)
|
|
|
|
GamesXChange.title.must_equal 'games-x-change'
|
|
|
|
end
|
|
|
|
end
|
2012-10-14 03:39:00 +08:00
|
|
|
end
|