Convert LanguageModuleRequirement test to spec.
This commit is contained in:
parent
398de9cf3c
commit
f33efbe7c4
49
Library/Homebrew/test/language_module_requirement_spec.rb
Normal file
49
Library/Homebrew/test/language_module_requirement_spec.rb
Normal file
@ -0,0 +1,49 @@
|
||||
require "requirements/language_module_requirement"
|
||||
|
||||
describe LanguageModuleRequirement do
|
||||
specify "unique dependencies are not equal" do
|
||||
x = described_class.new(:node, "less")
|
||||
y = described_class.new(:node, "coffee-script")
|
||||
expect(x).not_to eq(y)
|
||||
expect(x.hash).not_to eq(y.hash)
|
||||
end
|
||||
|
||||
context "when module and import name differ" do
|
||||
subject { described_class.new(:python, mod_name, import_name) }
|
||||
let(:mod_name) { "foo" }
|
||||
let(:import_name) { "bar" }
|
||||
|
||||
its(:message) { is_expected.to include(mod_name) }
|
||||
its(:the_test) { is_expected.to include("import #{import_name}") }
|
||||
end
|
||||
|
||||
context "when the language is Perl" do
|
||||
it "does not satisfy invalid dependencies" do
|
||||
expect(described_class.new(:perl, "notapackage")).not_to be_satisfied
|
||||
end
|
||||
|
||||
it "satisfies valid dependencies" do
|
||||
expect(described_class.new(:perl, "Env")).to be_satisfied
|
||||
end
|
||||
end
|
||||
|
||||
context "when the language is Python", :needs_python do
|
||||
it "does not satisfy invalid dependencies" do
|
||||
expect(described_class.new(:python, "notapackage")).not_to be_satisfied
|
||||
end
|
||||
|
||||
it "satisfies valid dependencies" do
|
||||
expect(described_class.new(:python, "datetime")).to be_satisfied
|
||||
end
|
||||
end
|
||||
|
||||
context "when the language is Ruby" do
|
||||
it "does not satisfy invalid dependencies" do
|
||||
expect(described_class.new(:ruby, "notapackage")).not_to be_satisfied
|
||||
end
|
||||
|
||||
it "satisfies valid dependencies" do
|
||||
expect(described_class.new(:ruby, "date")).to be_satisfied
|
||||
end
|
||||
end
|
||||
end
|
@ -1,55 +0,0 @@
|
||||
require "testing_env"
|
||||
require "requirements/language_module_requirement"
|
||||
|
||||
class LanguageModuleRequirementTests < Homebrew::TestCase
|
||||
parallelize_me!
|
||||
|
||||
def assert_deps_fail(spec)
|
||||
refute_predicate LanguageModuleRequirement.new(*spec.shift.reverse), :satisfied?
|
||||
end
|
||||
|
||||
def assert_deps_pass(spec)
|
||||
assert_predicate LanguageModuleRequirement.new(*spec.shift.reverse), :satisfied?
|
||||
end
|
||||
|
||||
def test_unique_deps_are_not_eql
|
||||
x = LanguageModuleRequirement.new(:node, "less")
|
||||
y = LanguageModuleRequirement.new(:node, "coffee-script")
|
||||
refute_eql x, y
|
||||
refute_equal x.hash, y.hash
|
||||
end
|
||||
|
||||
def test_differing_module_and_import_name
|
||||
mod_name = "foo"
|
||||
import_name = "bar"
|
||||
l = LanguageModuleRequirement.new(:python, mod_name, import_name)
|
||||
assert_includes l.message, mod_name
|
||||
assert_includes l.the_test, "import #{import_name}"
|
||||
end
|
||||
|
||||
def test_bad_perl_deps
|
||||
assert_deps_fail "notapackage" => :perl
|
||||
end
|
||||
|
||||
def test_good_perl_deps
|
||||
assert_deps_pass "Env" => :perl
|
||||
end
|
||||
|
||||
def test_bad_python_deps
|
||||
needs_python
|
||||
assert_deps_fail "notapackage" => :python
|
||||
end
|
||||
|
||||
def test_good_python_deps
|
||||
needs_python
|
||||
assert_deps_pass "datetime" => :python
|
||||
end
|
||||
|
||||
def test_bad_ruby_deps
|
||||
assert_deps_fail "notapackage" => :ruby
|
||||
end
|
||||
|
||||
def test_good_ruby_deps
|
||||
assert_deps_pass "date" => :ruby
|
||||
end
|
||||
end
|
@ -33,6 +33,10 @@ RSpec.configure do |config|
|
||||
if example.metadata[:needs_macos]
|
||||
skip "not on macOS" unless OS.mac?
|
||||
end
|
||||
|
||||
if example.metadata[:needs_python]
|
||||
skip "Python not installed." unless which("python")
|
||||
end
|
||||
end
|
||||
config.around(:each) do |example|
|
||||
begin
|
||||
|
Loading…
x
Reference in New Issue
Block a user