1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
# frozen_string_literal: true
require File.expand_path('setup', File.dirname(__FILE__))
require 'jars/maven_exec'
require 'fileutils'
require 'stringio'
describe Jars::MavenExec do
let(:pwd) { File.dirname(File.expand_path(__FILE__)) }
let(:example_spec) { File.join(pwd, '..', 'example', 'example.gemspec') }
let(:spec_with_require_relative) do
File.join(pwd, 'example', 'gem_with_require_relative', 'gem_with_require_relative.gemspec')
end
after do
Jars.reset
end
it 'should not warn if gemspec contains require_relative' do
Dir.chdir File.dirname(spec_with_require_relative) do
$stderr = StringIO.new
Jars::MavenExec.new
_($stderr.string).must_equal ''
ensure
$stderr = STDERR
end
end
it 'finds the gemspec file when the Gem::Specification.spec_file is wrong' do
spec = Dir.chdir(File.dirname(example_spec)) do
eval(File.read(example_spec)) # rubocop:disable Security/Eval
end
spec.loaded_from = spec.spec_file
# mimic bundler case
FileUtils.rm_f(spec.spec_file)
def spec.gem_dir=(dir)
@d = dir
end
def spec.gem_dir
@d
end
spec.gem_dir = File.dirname(example_spec)
# now test finding the gemspec file
jar = Jars::MavenExec.new(spec)
_(jar.instance_variable_get(:@basedir)).must_equal File.expand_path(spec.gem_dir)
_(jar.instance_variable_get(:@specfile)).must_equal File.expand_path(example_spec)
end
end
|