1
0
mirror of https://github.com/github/choosealicense.com synced 2024-12-22 04:40:09 +01:00

Test examples provided in 'using:' would be detected by licensee

This commit is contained in:
Mike Linksvayer 2017-11-25 16:16:11 -08:00
parent 7c25006fca
commit 7649067151
3 changed files with 29 additions and 2 deletions

View File

@ -16,6 +16,7 @@ end
group :test do
gem 'html-proofer', '~> 3.0'
gem 'licensee'
gem 'nokogiri'
gem 'rake'
gem 'rspec'

View File

@ -1,5 +1,6 @@
# frozen_string_literal: true
require 'licensee'
require 'spec_helper'
describe 'license meta' do
@ -19,6 +20,8 @@ describe 'license meta' do
expect(missing).to be_empty
end
examples = raw_fields['using'] || []
it 'using contains 3 examples' do
legacy = [
'afl-3.0',
@ -43,9 +46,33 @@ describe 'license meta' do
'zlib'
]
skip 'added before 3 using examples required' if legacy.include?(license['slug'])
examples = raw_fields['using'] || []
expect(examples.length).to eq(3)
end
context 'licensee detects using examples' do
module Licensee
class License
class << self
def license_dir
dir = ::File.dirname(__FILE__)
::File.expand_path '../_licenses', dir
end
end
end
end
examples.each do |example|
example_url = example.values[0]
if example_url.index('https://github.com/') == 0
example_url.gsub!(%r{\Ahttps://github.com/(\w+/\w+)/blob/(\w+/\S+)\z}, 'https://raw.githubusercontent.com/\1/\2')
end
content = open(example_url).read
detected = Licensee::ProjectFiles::LicenseFile.new(content, 'LICENSE').license
it example_url do
expect(detected.key).to eq(license['slug'])
end
end
end
end
end
end

View File

@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'jekyll'
require 'open-uri'
require 'json'
require 'open-uri'
require 'nokogiri'