Skip to content

Commit

Permalink
OMG a test suite!
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
phinze committed Oct 13, 2012
1 parent 0ec6e18 commit f1932a4
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source :rubygems

group :test do
gem 'purdytest'
end
12 changes: 12 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'rake/testtask'

Rake::TestTask.new do |t|
t.pattern = "spec/*_test.rb"
end

task :default => :test
4 changes: 3 additions & 1 deletion lib/cask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ def self.path(cask_title)
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

Expand Down
17 changes: 17 additions & 0 deletions spec/cask_test.rb
Original file line number Diff line number Diff line change
@@ -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 changes: 34 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions spec/support/homebrew
Submodule homebrew added at c40cff

0 comments on commit f1932a4

Please sign in to comment.