require 'spec_helper'
module LicenseFinder
describe Maven do
def license_xml(xml)
<<-resp
#{xml}
resp
end
describe '.current_packages' do
before do
expect(described_class).to receive(:`).with(/mvn/)
end
it 'lists all the current packages' do
license_xml = license_xml("""
junit
junit
4.11
Common Public License Version 1.0
http://www.opensource.org/licenses/cpl1.0.txt
org.hamcrest
hamcrest-core
1.3
New BSD License
http://www.opensource.org/licenses/bsd-license.php
repo
""")
allow(File).to receive(:read).with("target/generated-resources/licenses.xml").and_return(license_xml)
current_packages = Maven.current_packages
expect(current_packages.size).to eq(2)
expect(current_packages.first).to be_a(Package)
end
it "handles multiple licenses" do
license_xml = license_xml("""
License 1
License 2
""")
allow(File).to receive(:read).with("target/generated-resources/licenses.xml").and_return(license_xml)
MavenPackage.should_receive(:new).with("licenses" => [{"name" => "License 1"}, {"name" => "License 2"}])
Maven.current_packages
end
it "handles no licenses" do
license_xml = license_xml("""
""")
allow(File).to receive(:read).with("target/generated-resources/licenses.xml").and_return(license_xml)
MavenPackage.should_receive(:new).with("licenses" => {})
Maven.current_packages
end
end
describe '.active?' do
let(:package) { Pathname.new('pom.xml').expand_path }
context 'with a pom.xml file' do
before :each do
allow(File).to receive(:exists?).with(package).and_return(true)
end
it 'returns true' do
expect(Maven.active?).to eq(true)
end
end
context 'without a pom.xml file' do
before :each do
allow(File).to receive(:exists?).with(package).and_return(false)
end
it 'returns false' do
expect(Maven.active?).to eq(false)
end
end
end
end
end