From f1932a4d8c358be1f7a42b4bed7b5ee27c365c7c Mon Sep 17 00:00:00 2001 From: phinze Date: Sat, 13 Oct 2012 14:39:00 -0500 Subject: [PATCH] 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. --- Gemfile | 5 +++++ Gemfile.lock | 12 ++++++++++++ Rakefile | 7 +++++++ lib/cask.rb | 4 +++- spec/cask_test.rb | 17 +++++++++++++++++ spec/spec_helper.rb | 34 ++++++++++++++++++++++++++++++++++ spec/support/homebrew | 1 + 7 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 Rakefile create mode 100644 spec/cask_test.rb create mode 100644 spec/spec_helper.rb create mode 160000 spec/support/homebrew diff --git a/Gemfile b/Gemfile new file mode 100644 index 000000000..ddc1cf7c7 --- /dev/null +++ b/Gemfile @@ -0,0 +1,5 @@ +source :rubygems + +group :test do + gem 'purdytest' +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 000000000..f59b9535d --- /dev/null +++ b/Gemfile.lock @@ -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 diff --git a/Rakefile b/Rakefile new file mode 100644 index 000000000..a79685b1a --- /dev/null +++ b/Rakefile @@ -0,0 +1,7 @@ +require 'rake/testtask' + +Rake::TestTask.new do |t| + t.pattern = "spec/*_test.rb" +end + +task :default => :test diff --git a/lib/cask.rb b/lib/cask.rb index 0bf0bf6f8..238ad5a7c 100644 --- a/lib/cask.rb +++ b/lib/cask.rb @@ -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 diff --git a/spec/cask_test.rb b/spec/cask_test.rb new file mode 100644 index 000000000..495f1a079 --- /dev/null +++ b/spec/cask_test.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 000000000..4bb7eab87 --- /dev/null +++ b/spec/spec_helper.rb @@ -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 diff --git a/spec/support/homebrew b/spec/support/homebrew new file mode 160000 index 000000000..c40cff570 --- /dev/null +++ b/spec/support/homebrew @@ -0,0 +1 @@ +Subproject commit c40cff570b905b5e4a6b283edc703f7b84bd0001