Skip to content
Snippets Groups Projects
Commit 62984b95 authored by EricFromCanada's avatar EricFromCanada
Browse files

relocate requirement tests

parent 212367c1
No related branches found
No related tags found
No related merge requests found
# typed: false
# frozen_string_literal: true
require "cli/args"
require "requirements/java_requirement"
describe JavaRequirement do
subject { described_class.new([]) }
before do
ENV["JAVA_HOME"] = nil
end
describe "#message" do
its(:message) { is_expected.to match(/Java is required for this software./) }
end
describe "#inspect" do
subject { described_class.new(%w[1.7+]) }
its(:inspect) { is_expected.to eq('#<JavaRequirement: version="1.7+" []>') }
end
describe "#display_s" do
context "without specific version" do
its(:display_s) { is_expected.to eq("Java") }
end
context "with version 1.8" do
subject { described_class.new(%w[1.8]) }
its(:display_s) { is_expected.to eq("Java = 1.8") }
end
context "with version 1.8+" do
subject { described_class.new(%w[1.8+]) }
its(:display_s) { is_expected.to eq("Java >= 1.8") }
end
end
describe "#satisfied?" do
subject { described_class.new(%w[1.8]) }
it "returns false if no `java` executable can be found" do
allow(File).to receive(:executable?).and_return(false)
expect(subject).not_to be_satisfied
end
it "returns true if #preferred_java returns a path" do
allow(subject).to receive(:preferred_java).and_return(Pathname.new("/usr/bin/java"))
expect(subject).to be_satisfied
end
context "when #possible_javas contains paths" do
let(:path) { mktmpdir }
let(:java) { path/"java" }
def setup_java_with_version(version)
IO.write java, <<~SH
#!/bin/sh
echo 'java version "#{version}"' 1>&2
SH
FileUtils.chmod "+x", java
end
before do
allow(subject).to receive(:possible_javas).and_return([java])
end
context "and 1.7 is required" do
subject { described_class.new(%w[1.7]) }
it "returns false if all are lower" do
setup_java_with_version "1.6.0_5"
expect(subject).not_to be_satisfied
end
it "returns true if one is equal" do
setup_java_with_version "1.7.0_5"
expect(subject).to be_satisfied
end
it "returns false if all are higher" do
setup_java_with_version "1.8.0_5"
expect(subject).not_to be_satisfied
end
end
context "and 1.7+ is required" do
subject { described_class.new(%w[1.7+]) }
it "returns false if all are lower" do
setup_java_with_version "1.6.0_5"
expect(subject).not_to be_satisfied
end
it "returns true if one is equal" do
setup_java_with_version "1.7.0_5"
expect(subject).to be_satisfied
end
it "returns true if one is higher" do
setup_java_with_version "1.8.0_5"
expect(subject).to be_satisfied
end
end
end
end
describe "#suggestion" do
context "without specific version" do
its(:suggestion) { is_expected.to match(/brew cask install adoptopenjdk/) }
its(:cask) { is_expected.to eq("adoptopenjdk") }
end
context "with version 1.8" do
subject { described_class.new(%w[1.8]) }
its(:suggestion) { is_expected.to match(%r{brew cask install homebrew/cask-versions/adoptopenjdk8}) }
its(:cask) { is_expected.to eq("homebrew/cask-versions/adoptopenjdk8") }
end
context "with version 1.8+" do
subject { described_class.new(%w[1.8+]) }
its(:suggestion) { is_expected.to match(/brew cask install adoptopenjdk/) }
its(:cask) { is_expected.to eq("adoptopenjdk") }
end
end
end
# typed: false # typed: false
# frozen_string_literal: true # frozen_string_literal: true
require "cli/args"
require "requirements/java_requirement" require "requirements/java_requirement"
describe JavaRequirement do describe JavaRequirement do
describe "initialize" do subject { described_class.new([]) }
before do
ENV["JAVA_HOME"] = nil
end
describe "#initialize" do
it "parses '1.8' tag correctly" do it "parses '1.8' tag correctly" do
req = described_class.new(["1.8"]) req = described_class.new(["1.8"])
expect(req.display_s).to eq("Java = 1.8") expect(req.display_s).to eq("Java = 1.8")
...@@ -30,4 +37,122 @@ describe JavaRequirement do ...@@ -30,4 +37,122 @@ describe JavaRequirement do
expect(req.display_s).to eq("Java") expect(req.display_s).to eq("Java")
end end
end end
describe "#message" do
its(:message) { is_expected.to match(/Java is required for this software./) }
end
describe "#inspect" do
subject { described_class.new(%w[1.7+]) }
its(:inspect) { is_expected.to eq('#<JavaRequirement: version="1.7+" []>') }
end
describe "#display_s" do
context "without specific version" do
its(:display_s) { is_expected.to eq("Java") }
end
context "with version 1.8" do
subject { described_class.new(%w[1.8]) }
its(:display_s) { is_expected.to eq("Java = 1.8") }
end
context "with version 1.8+" do
subject { described_class.new(%w[1.8+]) }
its(:display_s) { is_expected.to eq("Java >= 1.8") }
end
end
describe "#satisfied?" do
subject(:requirement) { described_class.new(%w[1.8]) }
it "returns false if no `java` executable can be found" do
allow(File).to receive(:executable?).and_return(false)
expect(requirement).not_to be_satisfied
end
it "returns true if #preferred_java returns a path" do
allow(requirement).to receive(:preferred_java).and_return(Pathname.new("/usr/bin/java"))
expect(requirement).to be_satisfied
end
context "when #possible_javas contains paths" do
let(:path) { mktmpdir }
let(:java) { path/"java" }
def setup_java_with_version(version)
IO.write java, <<~SH
#!/bin/sh
echo 'java version "#{version}"' 1>&2
SH
FileUtils.chmod "+x", java
end
before do
allow(requirement).to receive(:possible_javas).and_return([java])
end
context "and 1.7 is required" do
subject(:requirement) { described_class.new(%w[1.7]) }
it "returns false if all are lower" do
setup_java_with_version "1.6.0_5"
expect(requirement).not_to be_satisfied
end
it "returns true if one is equal" do
setup_java_with_version "1.7.0_5"
expect(requirement).to be_satisfied
end
it "returns false if all are higher" do
setup_java_with_version "1.8.0_5"
expect(requirement).not_to be_satisfied
end
end
context "and 1.7+ is required" do
subject(:requirement) { described_class.new(%w[1.7+]) }
it "returns false if all are lower" do
setup_java_with_version "1.6.0_5"
expect(requirement).not_to be_satisfied
end
it "returns true if one is equal" do
setup_java_with_version "1.7.0_5"
expect(requirement).to be_satisfied
end
it "returns true if one is higher" do
setup_java_with_version "1.8.0_5"
expect(requirement).to be_satisfied
end
end
end
end
describe "#suggestion" do
context "without specific version" do
its(:suggestion) { is_expected.to match(/brew cask install adoptopenjdk/) }
its(:cask) { is_expected.to eq("adoptopenjdk") }
end
context "with version 1.8" do
subject { described_class.new(%w[1.8]) }
its(:suggestion) { is_expected.to match(%r{brew cask install homebrew/cask-versions/adoptopenjdk8}) }
its(:cask) { is_expected.to eq("homebrew/cask-versions/adoptopenjdk8") }
end
context "with version 1.8+" do
subject { described_class.new(%w[1.8+]) }
its(:suggestion) { is_expected.to match(/brew cask install adoptopenjdk/) }
its(:cask) { is_expected.to eq("adoptopenjdk") }
end
end
end end
...@@ -5,26 +5,28 @@ require "cli/args" ...@@ -5,26 +5,28 @@ require "cli/args"
require "requirements/x11_requirement" require "requirements/x11_requirement"
describe X11Requirement do describe X11Requirement do
subject(:requirement) { described_class.new([]) }
let(:default_name) { "x11" } let(:default_name) { "x11" }
describe "#name" do describe "#name" do
it "defaults to x11" do it "defaults to x11" do
expect(subject.name).to eq(default_name) expect(requirement.name).to eq(default_name)
end end
end end
describe "#eql?" do describe "#eql?" do
it "returns true if the requirements are equal" do it "returns true if the requirements are equal" do
other = described_class.new other = described_class.new
expect(subject).to eql(other) expect(requirement).to eql(other)
end end
end end
describe "#modify_build_environment" do describe "#modify_build_environment" do
it "calls ENV#x11" do it "calls ENV#x11" do
allow(subject).to receive(:satisfied?).and_return(true) allow(requirement).to receive(:satisfied?).and_return(true)
expect(ENV).to receive(:x11) expect(ENV).to receive(:x11)
subject.modify_build_environment requirement.modify_build_environment
end end
end end
...@@ -32,12 +34,12 @@ describe X11Requirement do ...@@ -32,12 +34,12 @@ describe X11Requirement do
it "returns true if X11 is installed" do it "returns true if X11 is installed" do
expect(MacOS::XQuartz).to receive(:version).and_return("2.7.5") expect(MacOS::XQuartz).to receive(:version).and_return("2.7.5")
expect(MacOS::XQuartz).to receive(:installed?).and_return(true) expect(MacOS::XQuartz).to receive(:installed?).and_return(true)
expect(subject).to be_satisfied expect(requirement).to be_satisfied
end end
it "returns false if X11 is not installed" do it "returns false if X11 is not installed" do
expect(MacOS::XQuartz).to receive(:installed?).and_return(false) expect(MacOS::XQuartz).to receive(:installed?).and_return(false)
expect(subject).not_to be_satisfied expect(requirement).not_to be_satisfied
end end
end end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment