Convert CompilerFailure test to spec.
This commit is contained in:
parent
c4cb1dd581
commit
262f357d86
41
Library/Homebrew/test/compiler_failure_spec.rb
Normal file
41
Library/Homebrew/test/compiler_failure_spec.rb
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
require "compilers"
|
||||||
|
|
||||||
|
describe CompilerFailure do
|
||||||
|
matcher :fail_with do |expected|
|
||||||
|
match do |actual|
|
||||||
|
actual.fails_with?(expected)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "::create" do
|
||||||
|
it "creates a failure when given a symbol" do
|
||||||
|
failure = described_class.create(:clang)
|
||||||
|
expect(failure).to fail_with(double("Compiler", name: :clang, version: 425))
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can be given a build number in a block" do
|
||||||
|
failure = described_class.create(:clang) { build 211 }
|
||||||
|
expect(failure).to fail_with(double("Compiler", name: :clang, version: 210))
|
||||||
|
expect(failure).not_to fail_with(double("Compiler", name: :clang, version: 318))
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can be given an empty block" do
|
||||||
|
failure = described_class.create(:clang) {}
|
||||||
|
expect(failure).to fail_with(double("Compiler", name: :clang, version: 425))
|
||||||
|
end
|
||||||
|
|
||||||
|
it "creates a failure when given a hash" do
|
||||||
|
failure = described_class.create(gcc: "4.8")
|
||||||
|
expect(failure).to fail_with(double("Compiler", name: "gcc-4.8", version: "4.8"))
|
||||||
|
expect(failure).to fail_with(double("Compiler", name: "gcc-4.8", version: "4.8.1"))
|
||||||
|
expect(failure).not_to fail_with(double("Compiler", name: "gcc-4.7", version: "4.7"))
|
||||||
|
end
|
||||||
|
|
||||||
|
it "creates a failure when given a hash and a block with aversion" do
|
||||||
|
failure = described_class.create(gcc: "4.8") { version "4.8.1" }
|
||||||
|
expect(failure).to fail_with(double("Compiler", name: "gcc-4.8", version: "4.8"))
|
||||||
|
expect(failure).to fail_with(double("Compiler", name: "gcc-4.8", version: "4.8.1"))
|
||||||
|
expect(failure).not_to fail_with(double("Compiler", name: "gcc-4.8", version: "4.8.2"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -1,52 +0,0 @@
|
|||||||
require "testing_env"
|
|
||||||
require "compilers"
|
|
||||||
|
|
||||||
class CompilerFailureTests < Homebrew::TestCase
|
|
||||||
Compiler = Struct.new(:name, :version)
|
|
||||||
|
|
||||||
def assert_fails_with(compiler, failure)
|
|
||||||
assert_operator failure, :fails_with?, compiler
|
|
||||||
end
|
|
||||||
|
|
||||||
def refute_fails_with(compiler, failure)
|
|
||||||
refute_operator failure, :fails_with?, compiler
|
|
||||||
end
|
|
||||||
|
|
||||||
def compiler(name, version)
|
|
||||||
Compiler.new(name, version)
|
|
||||||
end
|
|
||||||
|
|
||||||
def create(spec, &block)
|
|
||||||
CompilerFailure.create(spec, &block)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_create_with_symbol
|
|
||||||
failure = create(:clang)
|
|
||||||
assert_fails_with compiler(:clang, 425), failure
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_create_with_block
|
|
||||||
failure = create(:clang) { build 211 }
|
|
||||||
assert_fails_with compiler(:clang, 210), failure
|
|
||||||
refute_fails_with compiler(:clang, 318), failure
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_create_with_block_without_build
|
|
||||||
failure = create(:clang) {}
|
|
||||||
assert_fails_with compiler(:clang, 425), failure
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_create_with_hash
|
|
||||||
failure = create(gcc: "4.8")
|
|
||||||
assert_fails_with compiler("gcc-4.8", "4.8"), failure
|
|
||||||
assert_fails_with compiler("gcc-4.8", "4.8.1"), failure
|
|
||||||
refute_fails_with compiler("gcc-4.7", "4.7"), failure
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_create_with_hash_and_version
|
|
||||||
failure = create(gcc: "4.8") { version "4.8.1" }
|
|
||||||
assert_fails_with compiler("gcc-4.8", "4.8"), failure
|
|
||||||
assert_fails_with compiler("gcc-4.8", "4.8.1"), failure
|
|
||||||
refute_fails_with compiler("gcc-4.8", "4.8.2"), failure
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Loading…
x
Reference in New Issue
Block a user