1
0
mirror of https://github.com/github/choosealicense.com synced 2024-12-22 12:50:24 +01:00

use regex to check for BOM

This commit is contained in:
Ben Balter 2016-01-29 12:44:28 -05:00
parent b9cdd8cb08
commit 41a9f1a9d7
3 changed files with 16 additions and 11 deletions

View File

@ -1,16 +1,13 @@
require 'spec_helper' require 'spec_helper'
describe "license file" do describe "byte order marks" do
Dir["#{licenses_path}/*.txt"].each do |file|
bom = "\xEF\xBB\xBF".each_byte.to_a context "the #{File.basename(file, ".txt")} license" do
it "does not begin with a byte order mark" do
files = Dir["_licenses/*.txt"] bom = !!(File.open(file).read =~ /\A\xEF\xBB\xBF/)
msg = "License file begins with a Byte Order Mark. See http://stackoverflow.com/a/1068700."
files.each do |fn| expect(bom).to eql(false), msg
first3 = File.open(fn) {|f| f.read(3)} end
it "#{fn} should not have a byte order mark" do
expect(first3.each_byte.to_a).not_to eq(bom)
end end
end end
end end

View File

@ -2,6 +2,10 @@ require 'spec_helper'
describe "licenses" do describe "licenses" do
it "matches the number of files in the _licenses folder" do
expect(licenses.count).to eql(Dir["#{licenses_path}/*.txt"].count)
end
licenses.each do |license| licenses.each do |license|
context "The #{license["title"]} license" do context "The #{license["title"]} license" do

View File

@ -12,6 +12,10 @@ def source
File.expand_path("../", File.dirname(__FILE__)) File.expand_path("../", File.dirname(__FILE__))
end end
def licenses_path
File.expand_path "_licenses", source
end
def config def config
config = Jekyll::Configuration.new.read_config_file config_file config = Jekyll::Configuration.new.read_config_file config_file
config = Jekyll::Utils.deep_merge_hashes(config, {:source => source}) config = Jekyll::Utils.deep_merge_hashes(config, {:source => source})