require 'helper' require 'fileutils' class TestLicenseeProject < Minitest::Test [true, false].each do |as_git| describe(as_git ? "git" : "non-git") do def make_project(fixture_name, as_git) fixture = fixture_path fixture_name unless as_git dest = File.join("tmp", "fixtures", fixture_name) FileUtils.mkdir_p File.dirname(dest) system "git", "clone", "-q", fixture, dest FileUtils.rm_r File.join(dest, ".git") fixture = dest end Licensee::Project.new fixture end unless as_git def teardown FileUtils.rm_rf "tmp/fixtures" end end should "detect the license file" do project = make_project "licenses.git", as_git assert_instance_of Licensee::LicenseFile, project.license_file end should "detect the license" do project = make_project "licenses.git", as_git assert_equal "mit", project.license.key end should "return the license hash" do project = make_project "licenses.git", as_git assert_equal "LICENSE", project.send(:license_hash)[:name] end should "return the license blob" do project = make_project "licenses.git", as_git assert_equal 1077, project.send(:license_blob).size end should "return the license path" do project = make_project "licenses.git", as_git assert_equal "LICENSE", project.send(:license_path) end should "detect an atypically cased license file" do project = make_project "case-sensitive.git", as_git assert_instance_of Licensee::LicenseFile, project.license_file end should "detect MIT-LICENSE licensed projects" do project = make_project "named-license-file-prefix.git", as_git assert_equal "mit", project.license.key end should "detect LICENSE-MIT licensed projects" do project = make_project "named-license-file-suffix.git", as_git assert_equal "mit", project.license.key end should "not error out on repos with folders names license" do project = make_project "license-folder.git", as_git assert_equal nil, project.license end should "detect licence files" do project = make_project "licence.git", as_git assert_equal "mit", project.license.key end end end context "license filename matching" do # Standard license names ["license", "LICENSE", "LICENCE", "license.md", "unlicense", "unlicence", "copying", "copyRIGHT", "license.txt" ].each do |license| should "match #{license}" do assert Licensee::Project.license_file?(license) end end should "not match MIT-LICENSE" do refute Licensee::Project.license_file?("MIT-LICENSE") end # Abnormal license names [ "LICENSE-MIT", "MIT-LICENSE.txt", "mit-license-foo.md" ].each do |license| should "match #{license}" do assert Licensee::Project.maybe_license_file?(license) end end should "return the proper license files scores" do assert_equal 1, Licensee::Project.match_license_file("LICENSE.md") assert_equal 0.5, Licensee::Project.match_license_file("MIT-LICENSE") assert_equal 0, Licensee::Project.match_license_file("README.txt") end end end