forked from Homebrew/homebrew-cask
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
install rspec; move first few tests over
refs Homebrew#5080
- Loading branch information
Showing
14 changed files
with
187 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--color | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
require 'rake/testtask' | ||
require 'rspec/core/rake_task' | ||
|
||
Rake::TestTask.new do |t| | ||
t.pattern = "test/**/*_test.rb" | ||
t.libs << 'test' | ||
end | ||
|
||
task :default => :test | ||
RSpec::Core::RakeTask.new(:spec) | ||
|
||
task :default => [:test, :spec] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require 'spec_helper' | ||
|
||
describe Cask::CLI do | ||
it "lists the taps for casks that show up in two taps" do | ||
listing = Cask::CLI.nice_listing(%w[ | ||
caskroom/cask/adium | ||
caskroom/cask/google-chrome | ||
passcod/homebrew-cask/adium | ||
]) | ||
|
||
expect(listing).to eq(%w[ | ||
caskroom/cask/adium | ||
google-chrome | ||
passcod/cask/adium | ||
]) | ||
end | ||
|
||
describe ".process" do | ||
let(:noop_command) { double('CLI::Noop') } | ||
before { | ||
allow(Cask::CLI).to receive(:lookup_command) { noop_command } | ||
allow(noop_command).to receive(:run) | ||
} | ||
|
||
it "respects the env variable when choosing what appdir to create" do | ||
with_env_var('HOMEBREW_CASK_OPTS', "--appdir=/custom/appdir") do | ||
allow(Cask).to receive(:init) { | ||
expect(Cask.appdir.to_s).to eq('/custom/appdir') | ||
} | ||
Cask::CLI.process('noop') | ||
end | ||
end | ||
|
||
it "respects the ENV variable when choosing a non-default Caskroom location" do | ||
with_env_var 'HOMEBREW_CASK_OPTS', "--caskroom=/custom/caskdir" do | ||
allow(Cask).to receive(:init) { | ||
expect(Cask.caskroom.to_s).to eq('/custom/caskdir') | ||
} | ||
Cask::CLI.process('noop') | ||
end | ||
end | ||
|
||
it "exits with a status of 1 when something goes wrong" do | ||
Cask::CLI.expects(:exit).with(1) | ||
Cask::CLI.expects(:lookup_command).raises(CaskError) | ||
shutup { | ||
Cask::CLI.process('noop') | ||
} | ||
end | ||
end | ||
end |
8 changes: 4 additions & 4 deletions
8
test/cask/underscore_supporting_uri_test.rb → spec/cask/underscore_supporting_uri_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
require 'test_helper' | ||
require 'spec_helper' | ||
|
||
describe Cask::UnderscoreSupportingURI do | ||
describe 'parse' do | ||
it 'works like normal on normal URLs' do | ||
uri = Cask::UnderscoreSupportingURI.parse('http://example.com/TestCask.dmg') | ||
uri.must_equal URI('http://example.com/TestCask.dmg') | ||
expect(uri).to eq(URI('http://example.com/TestCask.dmg')) | ||
end | ||
|
||
it 'works just fine on URIs with underscores' do | ||
uri = Cask::UnderscoreSupportingURI.parse('http://dl_dir.qq.com/qqfile/qq/QQforMac/QQ_V3.0.0.dmg') | ||
uri.host.must_include '_' | ||
uri.to_s.must_equal 'http://dl_dir.qq.com/qqfile/qq/QQforMac/QQ_V3.0.0.dmg' | ||
expect(uri.host).to include('_') | ||
expect(uri.to_s).to eq('http://dl_dir.qq.com/qqfile/qq/QQforMac/QQ_V3.0.0.dmg') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
project_root = Pathname(File.expand_path("../..", __FILE__)) | ||
|
||
Dir["#{project_root}/spec/support/**/*.rb"].each { |f| require f } | ||
|
||
include HomebrewTestingEnvironment | ||
|
||
# add cask lib to load path | ||
$:.push(project_root.join('lib').to_s) | ||
|
||
require 'cask' | ||
|
||
# Look for casks in testcasks by default. It is elsewhere required that | ||
# the string "test" appear in the directory name. | ||
Cask.default_tap = 'caskroom/homebrew-testcasks' | ||
|
||
# our own testy caskroom | ||
Cask.caskroom = HOMEBREW_PREFIX.join('TestCaskroom') | ||
|
||
RSpec.configure do |config| | ||
config.include ShutupHelper | ||
config.include TempEnvVarHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module HomebrewTestingEnvironment | ||
def self.included(base) | ||
# force some environment variables | ||
ENV['HOMEBREW_NO_EMOJI']='1' | ||
|
||
# set some Homebrew constants used in our code | ||
base.const_set('HOMEBREW_BREW_FILE', '/usr/local/bin/brew') | ||
|
||
# add homebrew to load path | ||
homebrew_path = Pathname(`brew --prefix`.chomp) | ||
homebrew_path = Pathname('/usr/local') unless homebrew_path.exist? | ||
$:.push(homebrew_path.join('Library', 'Homebrew')) | ||
|
||
# require homebrew testing env | ||
with_disabled_at_exit do | ||
require 'test/testing_env' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Kernel | ||
alias_method :real_at_exit, :at_exit | ||
|
||
def at_exit(&block) | ||
unless ENV['DISABLE_AT_EXIT'] | ||
real_at_exit(&block) | ||
end | ||
end | ||
|
||
def with_disabled_at_exit(&block) | ||
ENV['DISABLE_AT_EXIT'] = '1' | ||
yield | ||
ENV.delete('DISABLE_AT_EXIT') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module ShutupHelper | ||
def shutup | ||
if ARGV.verbose? | ||
yield | ||
else | ||
begin | ||
tmperr = $stderr.clone | ||
tmpout = $stdout.clone | ||
$stderr.reopen '/dev/null', 'w' | ||
$stdout.reopen '/dev/null', 'w' | ||
yield | ||
ensure | ||
$stderr.reopen tmperr | ||
$stdout.reopen tmpout | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module TempEnvVarHelper | ||
def with_env_var(key, val, &block) | ||
was_defined = ENV.key? 'key' | ||
old_value = ENV['key'] | ||
ENV[key] = val | ||
block.call | ||
ensure | ||
if was_defined | ||
ENV[key] = old_value | ||
else | ||
ENV.delete(key) | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.