Move test helpers into Homebrew::TestCase

This commit is contained in:
Jack Nagel 2014-06-18 20:32:51 -05:00
parent 982e9239b8
commit 89d74ec475
5 changed files with 38 additions and 53 deletions

View File

@ -2,8 +2,6 @@ require 'testing_env'
require 'test/testball'
class FormulaTests < Homebrew::TestCase
include VersionAssertions
def test_formula_instantiation
klass = Class.new(Formula) { url "http://example.com/foo-1.0.tar.gz" }
name = "formula_name"

View File

@ -2,8 +2,6 @@ require 'testing_env'
require 'resource'
class ResourceTests < Homebrew::TestCase
include VersionAssertions
def setup
@resource = Resource.new('test')
end

View File

@ -2,8 +2,6 @@ require 'testing_env'
require 'software_spec'
class SoftwareSpecTests < Homebrew::TestCase
include VersionAssertions
def setup
@spec = SoftwareSpec.new
end
@ -88,8 +86,6 @@ class SoftwareSpecTests < Homebrew::TestCase
end
class HeadSoftwareSpecTests < Homebrew::TestCase
include VersionAssertions
def setup
@spec = HeadSoftwareSpec.new
end

View File

@ -2,8 +2,6 @@ require 'testing_env'
require 'version'
class VersionTests < Homebrew::TestCase
include VersionAssertions
def test_accepts_objects_responding_to_to_str
value = stub(:to_str => '0.1')
assert_equal '0.1', Version.new(value).to_s
@ -29,8 +27,6 @@ class VersionTests < Homebrew::TestCase
end
class VersionComparisonTests < Homebrew::TestCase
include VersionAssertions
def test_version_comparisons
assert_operator version('0.1'), :==, version('0.1.0')
assert_operator version('0.1'), :<, version('0.2')
@ -96,8 +92,6 @@ class VersionComparisonTests < Homebrew::TestCase
end
class VersionParsingTests < Homebrew::TestCase
include VersionAssertions
def test_pathname_version
d = HOMEBREW_CELLAR/'foo-0.1.9'
d.mkpath

View File

@ -56,23 +56,6 @@ at_exit { HOMEBREW_PREFIX.parent.rmtree }
# Test fixtures and files can be found relative to this path
TEST_DIRECTORY = File.dirname(File.expand_path(__FILE__))
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
require 'test/unit' # must be after at_exit
require 'extend/ARGV' # needs to be after test/unit to avoid conflict with OptionsParser
ARGV.extend(HomebrewArgvExtension)
@ -84,7 +67,15 @@ rescue LoadError
warn 'The mocha gem is required to run some tests, expect failures'
end
module VersionAssertions
module Test::Unit::Assertions
def assert_empty(obj, msg=nil)
assert_respond_to(obj, :empty?, msg)
assert(obj.empty?, msg)
end unless method_defined?(:assert_empty)
end
module Homebrew
module VersionAssertions
def version v
Version.new(v)
end
@ -104,22 +95,30 @@ module VersionAssertions
def assert_version_tokens tokens, version
assert_equal tokens, version.send(:tokens).map(&:to_s)
end
end
end
module Test::Unit::Assertions
def assert_empty(obj, msg=nil)
assert_respond_to(obj, :empty?, msg)
assert(obj.empty?, msg)
end unless method_defined?(:assert_empty)
end
module Homebrew
class TestCase < ::Test::Unit::TestCase
include VersionAssertions
TEST_SHA1 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef".freeze
TEST_SHA256 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef".freeze
def formula(name="formula_name", path=Formula.path(name), &block)
@_f = Class.new(Formula, &block).new(name, path)
end
def shutup
err = $stderr.clone
out = $stdout.clone
begin
$stderr.reopen("/dev/null", "w")
$stdout.reopen("/dev/null", "w")
yield
ensure
$stderr.reopen(err)
$stdout.reopen(out)
end
end
end
end