Skip to content

Commit 58d4c74

Browse files
committed
install rspec; move first few tests over
refs Homebrew#5080
1 parent c51d9b2 commit 58d4c74

14 files changed

+187
-95
lines changed

.rspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--color
2+
--require spec_helper

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ group :test do
44
gem 'rake'
55
gem 'minitest', '5.3'
66
gem 'minitest-colorize'
7-
gem 'mocha', '0.14.0'
7+
gem 'mocha', '0.14.0', :require => false
8+
gem 'rspec', '~> 3.0.0'
89
end

Gemfile.lock

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4+
diff-lcs (1.2.5)
45
metaclass (0.0.1)
56
minitest (5.3)
67
minitest-colorize (0.0.5)
78
minitest (>= 2.0)
89
mocha (0.14.0)
910
metaclass (~> 0.0.1)
1011
rake (10.0.4)
12+
rspec (3.0.0)
13+
rspec-core (~> 3.0.0)
14+
rspec-expectations (~> 3.0.0)
15+
rspec-mocks (~> 3.0.0)
16+
rspec-core (3.0.2)
17+
rspec-support (~> 3.0.0)
18+
rspec-expectations (3.0.2)
19+
diff-lcs (>= 1.2.0, < 2.0)
20+
rspec-support (~> 3.0.0)
21+
rspec-mocks (3.0.2)
22+
rspec-support (~> 3.0.0)
23+
rspec-support (3.0.2)
1124

1225
PLATFORMS
1326
ruby
@@ -17,3 +30,4 @@ DEPENDENCIES
1730
minitest-colorize
1831
mocha (= 0.14.0)
1932
rake
33+
rspec (~> 3.0.0)

Rakefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
require 'rake/testtask'
2+
require 'rspec/core/rake_task'
23

34
Rake::TestTask.new do |t|
45
t.pattern = "test/**/*_test.rb"
56
t.libs << 'test'
67
end
78

8-
task :default => :test
9+
RSpec::Core::RakeTask.new(:spec)
10+
11+
task :default => [:test, :spec]

test/cask/audit_test.rb renamed to spec/cask/audit_spec.rb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'test_helper'
1+
require 'spec_helper'
22

33
class CaskMissingUrl < Cask
44
version '1.2.3'
@@ -46,21 +46,21 @@ class CaskWithVersionNoChecksum < Cask
4646
describe Cask::Audit do
4747
describe "result" do
4848
it "is 'failed' if there are have been any errors added" do
49-
audit = Cask::Audit.new(TestHelper.test_cask)
49+
audit = Cask::Audit.new(Cask.new)
5050
audit.add_error 'bad'
5151
audit.add_warning 'eh'
52-
audit.result.must_match /failed/
52+
expect(audit.result).to match(/failed/)
5353
end
5454

5555
it "is 'warning' if there are no errors, but there are warnings" do
56-
audit = Cask::Audit.new(TestHelper.test_cask)
56+
audit = Cask::Audit.new(Cask.new)
5757
audit.add_warning 'eh'
58-
audit.result.must_match /warning/
58+
expect(audit.result).to match(/warning/)
5959
end
6060

6161
it "is 'passed' if there are no errors or warning" do
62-
audit = Cask::Audit.new(TestHelper.test_cask)
63-
audit.result.must_match /passed/
62+
audit = Cask::Audit.new(Cask.new)
63+
expect(audit.result).to match(/passed/)
6464
end
6565
end
6666

@@ -69,31 +69,31 @@ class CaskWithVersionNoChecksum < Cask
6969
it "adds an error if url is missing" do
7070
audit = Cask::Audit.new(CaskMissingUrl.new)
7171
audit.run!
72-
audit.errors.must_include 'url is required'
72+
expect(audit.errors).to include('url is required')
7373
end
7474

7575
it "adds an error if version is missing" do
7676
audit = Cask::Audit.new(CaskMissingVersion.new)
7777
audit.run!
78-
audit.errors.must_include 'version is required'
78+
expect(audit.errors).to include('version is required')
7979
end
8080

8181
it "adds an error if homepage is missing" do
8282
audit = Cask::Audit.new(CaskMissingHomepage.new)
8383
audit.run!
84-
audit.errors.must_include 'homepage is required'
84+
expect(audit.errors).to include('homepage is required')
8585
end
8686

8787
it "adds an error if version is latest and using sha256" do
8888
audit = Cask::Audit.new(CaskVersionLatestWithChecksum.new)
8989
audit.run!
90-
audit.errors.must_include %q{you should use sha256 :no_check when version is 'latest'}
90+
expect(audit.errors).to include(%q{you should use sha256 :no_check when version is 'latest'})
9191
end
9292

9393
it "adds an error if versioned and has no checksum" do
9494
audit = Cask::Audit.new(CaskWithVersionNoChecksum.new)
9595
audit.run!
96-
audit.errors.must_include %q{you must include a sha256 when version is not 'latest'}
96+
expect(audit.errors).to include(%q{you must include a sha256 when version is not 'latest'})
9797
end
9898
end
9999

@@ -104,27 +104,27 @@ class CaskWithVersionNoChecksum < Cask
104104

105105
audit = Cask::Audit.new(CaskSourceForgeIncorrectURLFormat.new)
106106
audit.run!
107-
audit.warnings.must_include warning_msg
107+
expect(audit.warnings).to include(warning_msg)
108108

109109
audit = Cask::Audit.new(CaskSourceForgeCorrectURLFormat.new)
110110
audit.run!
111-
audit.warnings.wont_include warning_msg
111+
expect(audit.warnings).to_not include(warning_msg)
112112

113113
audit = Cask::Audit.new(CaskSourceForgeOtherCorrectURLFormat.new)
114114
audit.run!
115-
audit.warnings.wont_include warning_msg
115+
expect(audit.warnings).to_not include(warning_msg)
116116
end
117117
end
118118

119119
describe "audit of downloads" do
120120
it "creates an error if the download fails" do
121121
error_message = "Download Failed"
122-
download = mock()
122+
download = double()
123123
download.expects(:perform).raises(StandardError.new(error_message))
124124

125-
audit = Cask::Audit.new(TestHelper.test_cask)
125+
audit = Cask::Audit.new(Cask.new)
126126
audit.run!(download)
127-
audit.errors.first.must_match(/#{error_message}/)
127+
expect(audit.errors).to include(/#{error_message}/)
128128
end
129129
end
130130
end

spec/cask/cli_spec.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
require 'spec_helper'
2+
3+
describe Cask::CLI do
4+
it "lists the taps for casks that show up in two taps" do
5+
listing = Cask::CLI.nice_listing(%w[
6+
caskroom/cask/adium
7+
caskroom/cask/google-chrome
8+
passcod/homebrew-cask/adium
9+
])
10+
11+
expect(listing).to eq(%w[
12+
caskroom/cask/adium
13+
google-chrome
14+
passcod/cask/adium
15+
])
16+
end
17+
18+
describe ".process" do
19+
let(:noop_command) { double('CLI::Noop') }
20+
before {
21+
allow(Cask::CLI).to receive(:lookup_command) { noop_command }
22+
allow(noop_command).to receive(:run)
23+
}
24+
25+
it "respects the env variable when choosing what appdir to create" do
26+
with_env_var('HOMEBREW_CASK_OPTS', "--appdir=/custom/appdir") do
27+
allow(Cask).to receive(:init) {
28+
expect(Cask.appdir.to_s).to eq('/custom/appdir')
29+
}
30+
Cask::CLI.process('noop')
31+
end
32+
end
33+
34+
it "respects the ENV variable when choosing a non-default Caskroom location" do
35+
with_env_var 'HOMEBREW_CASK_OPTS', "--caskroom=/custom/caskdir" do
36+
allow(Cask).to receive(:init) {
37+
expect(Cask.caskroom.to_s).to eq('/custom/caskdir')
38+
}
39+
Cask::CLI.process('noop')
40+
end
41+
end
42+
43+
it "exits with a status of 1 when something goes wrong" do
44+
Cask::CLI.expects(:exit).with(1)
45+
Cask::CLI.expects(:lookup_command).raises(CaskError)
46+
shutup {
47+
Cask::CLI.process('noop')
48+
}
49+
end
50+
end
51+
end
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
require 'test_helper'
1+
require 'spec_helper'
22

33
describe Cask::UnderscoreSupportingURI do
44
describe 'parse' do
55
it 'works like normal on normal URLs' do
66
uri = Cask::UnderscoreSupportingURI.parse('http://example.com/TestCask.dmg')
7-
uri.must_equal URI('http://example.com/TestCask.dmg')
7+
expect(uri).to eq(URI('http://example.com/TestCask.dmg'))
88
end
99

1010
it 'works just fine on URIs with underscores' do
1111
uri = Cask::UnderscoreSupportingURI.parse('http://dl_dir.qq.com/qqfile/qq/QQforMac/QQ_V3.0.0.dmg')
12-
uri.host.must_include '_'
13-
uri.to_s.must_equal 'http://dl_dir.qq.com/qqfile/qq/QQforMac/QQ_V3.0.0.dmg'
12+
expect(uri.host).to include('_')
13+
expect(uri.to_s).to eq('http://dl_dir.qq.com/qqfile/qq/QQforMac/QQ_V3.0.0.dmg')
1414
end
1515
end
1616
end

spec/spec_helper.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
project_root = Pathname(File.expand_path("../..", __FILE__))
2+
3+
Dir["#{project_root}/spec/support/**/*.rb"].each { |f| require f }
4+
5+
include HomebrewTestingEnvironment
6+
7+
# add cask lib to load path
8+
$:.push(project_root.join('lib').to_s)
9+
10+
require 'cask'
11+
12+
# Look for casks in testcasks by default. It is elsewhere required that
13+
# the string "test" appear in the directory name.
14+
Cask.default_tap = 'caskroom/homebrew-testcasks'
15+
16+
# our own testy caskroom
17+
Cask.caskroom = HOMEBREW_PREFIX.join('TestCaskroom')
18+
19+
RSpec.configure do |config|
20+
config.include ShutupHelper
21+
config.include TempEnvVarHelper
22+
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module HomebrewTestingEnvironment
2+
def self.included(base)
3+
# force some environment variables
4+
ENV['HOMEBREW_NO_EMOJI']='1'
5+
6+
# set some Homebrew constants used in our code
7+
base.const_set('HOMEBREW_BREW_FILE', '/usr/local/bin/brew')
8+
9+
# add homebrew to load path
10+
homebrew_path = Pathname(`brew --prefix`.chomp)
11+
homebrew_path = Pathname('/usr/local') unless homebrew_path.exist?
12+
$:.push(homebrew_path.join('Library', 'Homebrew'))
13+
14+
# require homebrew testing env
15+
with_disabled_at_exit do
16+
require 'test/testing_env'
17+
end
18+
end
19+
end

spec/support/kernel_at_exit_hacks.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Kernel
2+
alias_method :real_at_exit, :at_exit
3+
4+
def at_exit(&block)
5+
unless ENV['DISABLE_AT_EXIT']
6+
real_at_exit(&block)
7+
end
8+
end
9+
10+
def with_disabled_at_exit(&block)
11+
ENV['DISABLE_AT_EXIT'] = '1'
12+
yield
13+
ENV.delete('DISABLE_AT_EXIT')
14+
end
15+
end

0 commit comments

Comments
 (0)