Skip to content
Snippets Groups Projects
Commit 445281f7 authored by Markus Reiter's avatar Markus Reiter Committed by GitHub
Browse files

Merge pull request #2074 from reitermarkus/spec-java_requirement

Convert JavaRequirement test to spec.
parents 6d4aa91b 9c1db3c8
No related branches found
No related tags found
No related merge requests found
require "requirements/java_requirement"
require "fileutils"
describe JavaRequirement do
subject { described_class.new(%w[1.8]) }
let(:java_home) { Dir.mktmpdir }
let(:java_home_path) { Pathname.new(java_home) }
before(:each) do
FileUtils.mkdir java_home_path/"bin"
FileUtils.touch java_home_path/"bin/java"
allow(subject).to receive(:preferred_java).and_return(java_home_path/"bin/java")
expect(subject).to be_satisfied
end
after(:each) { java_home_path.rmtree }
specify "Apple Java environment" do
expect(ENV).to receive(:prepend_path)
expect(ENV).to receive(:append_to_cflags)
subject.modify_build_environment
expect(ENV["JAVA_HOME"]).to eq(java_home)
end
specify "Oracle Java environment" do
FileUtils.mkdir java_home_path/"include"
expect(ENV).to receive(:prepend_path)
expect(ENV).to receive(:append_to_cflags).twice
subject.modify_build_environment
expect(ENV["JAVA_HOME"]).to eq(java_home)
end
end
require "testing_env"
require "requirements/java_requirement"
require "fileutils"
class OSMacJavaRequirementTests < Homebrew::TestCase
def setup
super
@java_req = JavaRequirement.new(%w[1.8])
@tmp_java_home = mktmpdir
@tmp_pathname = Pathname.new(@tmp_java_home)
FileUtils.mkdir @tmp_pathname/"bin"
FileUtils.touch @tmp_pathname/"bin/java"
@java_req.stubs(:preferred_java).returns(@tmp_pathname/"bin/java")
@java_req.satisfied?
end
def test_java_env_apple
ENV.expects(:prepend_path)
ENV.expects(:append_to_cflags)
@java_req.modify_build_environment
assert_equal ENV["JAVA_HOME"], @tmp_java_home
end
def test_java_env_oracle
FileUtils.mkdir @tmp_pathname/"include"
ENV.expects(:prepend_path)
ENV.expects(:append_to_cflags).twice
@java_req.modify_build_environment
assert_equal ENV["JAVA_HOME"], @tmp_java_home
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