OMG a test suite!

Just getting started of course, but this piggy backs on Homebrew's
testing strategy to give us a platform for a fully featured test suite.
Neato!

And the tests provide value right away, as I added some better error
handling to `Cask.load`.

Big things ahead. Just you wait.
This commit is contained in:
phinze 2012-10-13 14:39:00 -05:00
parent 0ec6e18fde
commit f1932a4d8c
7 changed files with 79 additions and 1 deletions

5
Gemfile Normal file
View File

@ -0,0 +1,5 @@
source :rubygems
group :test do
gem 'purdytest'
end

12
Gemfile.lock Normal file
View File

@ -0,0 +1,12 @@
GEM
remote: http://rubygems.org/
specs:
minitest (2.12.1)
purdytest (1.0.0)
minitest (~> 2.2)
PLATFORMS
ruby
DEPENDENCIES
purdytest

7
Rakefile Normal file
View File

@ -0,0 +1,7 @@
require 'rake/testtask'
Rake::TestTask.new do |t|
t.pattern = "spec/*_test.rb"
end
task :default => :test

View File

@ -80,7 +80,9 @@ class Cask
end
def self.load(cask_title)
require path cask_title
cask_path = path(cask_title)
raise CaskUnavailableError, cask_title unless cask_path
require cask_path
const_get(cask_title.split('/').last.split('-').map(&:capitalize).join).new
end

17
spec/cask_test.rb Normal file
View File

@ -0,0 +1,17 @@
require_relative 'spec_helper'
describe Cask do
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
it "raises an error when attempting to load a cask that doesn't exist" do
lambda {
Cask.load("notacask")
}.must_raise(CaskUnavailableError)
end
end
end

34
spec/spec_helper.rb Normal file
View File

@ -0,0 +1,34 @@
require 'bundler/setup'
require 'pp'
# add cask lib to load path
brew_cask_path = Pathname.new(File.expand_path(__FILE__+'/../../'))
casks_path = brew_cask_path.join('casks')
lib_path = brew_cask_path.join('lib')
$:.push(lib_path)
# add vendored homebrew to load path
homebrew_path = brew_cask_path.join('spec', 'support', 'homebrew')
$:.push(homebrew_path.join('Library', 'Homebrew'))
# require homebrew testing env
require 'test/testing_env'
# add in HOMEBREW_LIBRARY constant, which is for some reason not set in testing_env
HOMEBREW_LIBRARY = HOMEBREW_REPOSITORY/"Library"
# must be called after testing_env so at_exit hooks are in proper order
require 'minitest/spec'
require 'minitest/autorun'
require 'purdytest'
# our baby
require 'cask'
# "install" brew-cask into homebrew testing env
require 'cmd/tap'
shutup do
Homebrew.install_tap 'phinze', 'cask'
end

1
spec/support/homebrew Submodule

@ -0,0 +1 @@
Subproject commit c40cff570b905b5e4a6b283edc703f7b84bd0001