test/functions.rb in licensee-6.1.1 vs test/functions.rb in licensee-7.0.0
- old
+ new
@@ -2,34 +2,34 @@
require 'securerandom'
require_relative '../lib/licensee'
def fixtures_base
- File.expand_path "fixtures", File.dirname( __FILE__ )
+ File.expand_path 'fixtures', File.dirname(__FILE__)
end
def fixture_path(fixture)
File.expand_path fixture, fixtures_base
end
def license_from_path(path)
license = File.open(path).read.match(/\A(---\n.*\n---\n+)?(.*)/m).to_a[2]
- license.sub! "[fullname]", "Ben Balter"
- license.sub! "[year]", "2014"
- license.sub! "[email]", "ben@github.invalid"
+ license.sub! '[fullname]', 'Ben Balter'
+ license.sub! '[year]', '2014'
+ license.sub! '[email]', 'ben@github.invalid'
license
end
def chaos_monkey(string)
Random.rand(3).times do
string[Random.rand(string.length)] = SecureRandom.base64(Random.rand(3))
end
string
end
-def verify_license_file(license, chaos = false, wrap=false)
- expected = File.basename(license, ".txt")
+def verify_license_file(license, chaos = false, wrap = false)
+ expected = File.basename(license, '.txt')
text = license_from_path(license)
text = chaos_monkey(text) if chaos
text = wrap(text, wrap) if wrap
@@ -37,19 +37,30 @@
actual = license_file.license
msg = "No match for #{expected}."
assert actual, msg
- assert_equal expected, actual.key, "expeceted #{expected} but got #{actual.key} for .match. Confidence: #{license_file.confidence}. Method: #{license_file.matcher.class}"
+
+ msg = "Expeceted #{expected} but got #{actual.key} for .match. "
+ msg << "Confidence: #{license_file.confidence}. "
+ msg << "Method: #{license_file.matcher.class}"
+ assert_equal expected, actual.key, msg
end
-def wrap(text, line_width=80)
+def wrap(text, line_width = 80)
text = text.clone
copyright = /^#{Licensee::Matchers::Copyright::REGEX}$/i.match(text)
- text.gsub! /^#{Licensee::Matchers::Copyright::REGEX}$/i, '[COPYRIGHT]' if copyright
- text.gsub! /([^\n])\n([^\n])/, '\1 \2'
+ if copyright
+ text.gsub!(/^#{Licensee::Matchers::Copyright::REGEX}$/i, '[COPYRIGHT]')
+ end
+ text.gsub!(/([^\n])\n([^\n])/, '\1 \2')
+
text = text.split("\n").collect do |line|
- line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip : line
+ if line.length > line_width
+ line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip
+ else
+ line
+ end
end * "\n"
- text.gsub! "[COPYRIGHT]", "\n#{copyright}\n" if copyright
+ text.gsub! '[COPYRIGHT]', "\n#{copyright}\n" if copyright
text.strip
end