binary_test (minitest) -> binary_spec (rspec)

This commit is contained in:
Radek Simko 2015-01-24 16:00:25 +00:00
parent 5496c8f531
commit 6b3146aed6
6 changed files with 34 additions and 26 deletions

View File

@ -1,21 +1,27 @@
require 'test_helper'
require 'spec_helper'
describe Hbc::Artifact::App do
describe Hbc::Artifact::Binary do
let(:cask) {
Hbc.load('with-binary').tap do |cask|
TestHelper.install_without_artifacts(cask)
shutup do
InstallHelper::install_without_artifacts(cask)
end
end
}
let(:expected_path) {
Hbc.binarydir.join('binary')
}
after(:each) {
if expected_path.exist?
FileUtils.rm expected_path
end
}
it "links the binary to the proper directory" do
shutup do
Hbc::Artifact::Binary.new(cask).install_phase
end
TestHelper.valid_alias?(expected_path).must_equal true
expect(FileHelper.valid_alias?(expected_path)).to be true
end
it "avoids clobbering an existing binary by linking over it" do
@ -25,7 +31,7 @@ describe Hbc::Artifact::App do
Hbc::Artifact::Binary.new(cask).install_phase
end
expected_path.wont_be :symlink?
expect(expected_path).to_not be :symlink?
end
it "clobbers an existing symlink" do
@ -35,7 +41,7 @@ describe Hbc::Artifact::App do
Hbc::Artifact::Binary.new(cask).install_phase
end
File.readlink(expected_path).wont_equal '/tmp'
expect(File.readlink(expected_path)).not_to eq('/tmp')
end
it "respects --no-binaries flag" do
@ -45,7 +51,7 @@ describe Hbc::Artifact::App do
Hbc::Artifact::Binary.new(cask).install_phase
end
expected_path.exist?.must_equal false
expect(expected_path.exist?).to be false
Hbc.no_binaries = false
end

View File

@ -6,9 +6,8 @@ end
project_root = Pathname(File.expand_path("../..", __FILE__))
Dir["#{project_root}/spec/support/**/*.rb"].each { |f| require f }
Dir["#{project_root}/spec/support/*.rb"].each { |f| require f }
include FileHelper
include HomebrewTestingEnvironment
# from Homebrew. Provides expects method.
require 'mocha/api'
@ -18,10 +17,13 @@ $:.push(project_root.join('lib').to_s)
require 'hbc'
class TestHbc < Hbc; end
# override Homebrew locations
Hbc.homebrew_prefix = Pathname.new(TEST_TMPDIR).join('prefix')
Hbc.homebrew_repository = Hbc.homebrew_prefix
Hbc.homebrew_tapspath = nil
Hbc.binarydir = Hbc.homebrew_prefix.join('binarydir').join('bin')
# making homebrew's cache dir allows us to actually download Casks in tests
HOMEBREW_CACHE.mkpath
@ -29,14 +31,12 @@ HOMEBREW_CACHE.join('Casks').mkpath
# Look for Casks in testcasks by default. It is elsewhere required that
# the string "test" appear in the directory name.
Hbc.default_tap = 'caskroom/homebrew-testcasks'
Hbc.default_tap = project_root.join('spec', 'support')
# our own testy caskroom
Hbc.caskroom = Hbc.homebrew_prefix.join('TestCaskroom')
RSpec.configure do |config|
config.include FileHelper
config.include InstallHelper
config.include ShutupHelper
config.include TempEnvVarHelper
end

View File

@ -2,7 +2,7 @@ cask :v1test => 'with-binary' do
version '1.2.3'
sha256 'd5b2dfbef7ea28c25f7a77cd7fa14d013d82b626db1d82e00e25822464ba19e2'
url TestHelper.local_binary_url('AppWithBinary.zip')
url FileHelper.local_binary_url('AppWithBinary.zip')
homepage 'http://example.com/with-binary'
app 'App.app'

View File

@ -1,14 +1,16 @@
module FileHelper
def local_binary_path(name)
File.expand_path(File.join(File.dirname(__FILE__), 'binaries', name))
end
class << self
def local_binary_path(name)
File.expand_path(File.join(File.dirname(__FILE__), 'binaries', name))
end
def local_binary_url(name)
'file://' + local_binary_path(name)
end
def local_binary_url(name)
'file://' + local_binary_path(name)
end
def valid_alias?(candidate)
return false unless candidate.symlink?
candidate.readlink.exist?
def valid_alias?(candidate)
return false unless candidate.symlink?
candidate.readlink.exist?
end
end
end

View File

@ -1,7 +1,7 @@
module InstallHelper
def install_without_artifacts(cask)
Hbc::Installer.new(cask).tap do |i|
shutup do
class << self
def install_without_artifacts(cask)
Hbc::Installer.new(cask).tap do |i|
i.download
i.extract_primary_container
end