From 764906715176b53843e73ef57956aabff7692cd4 Mon Sep 17 00:00:00 2001 From: Mike Linksvayer Date: Sat, 25 Nov 2017 16:16:11 -0800 Subject: [PATCH] Test examples provided in 'using:' would be detected by licensee --- Gemfile | 1 + spec/license_meta_spec.rb | 29 ++++++++++++++++++++++++++++- spec/spec_helper.rb | 1 - 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 84fd12d..c92472d 100644 --- a/Gemfile +++ b/Gemfile @@ -16,6 +16,7 @@ end group :test do gem 'html-proofer', '~> 3.0' + gem 'licensee' gem 'nokogiri' gem 'rake' gem 'rspec' diff --git a/spec/license_meta_spec.rb b/spec/license_meta_spec.rb index b705913..6604066 100644 --- a/spec/license_meta_spec.rb +++ b/spec/license_meta_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ab89492..4070ccf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'jekyll' -require 'open-uri' require 'json' require 'open-uri' require 'nokogiri'