spec/spec_helper.rb in licensee-8.9.2 vs spec/spec_helper.rb in licensee-9.0.0.beta.1
- old
+ new
@@ -34,33 +34,20 @@
text.sub! '[year]', '2016'
text.sub! '[email]', 'ben@github.invalid'
text
end
-def wrap(text, line_width = 80)
- text = text.clone
- text.gsub!(/([^\n])\n([^\n])/, '\1 \2')
-
- text = text.split("\n").collect do |line|
- if line.length > line_width
- line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip
- else
- line
- end
- end * "\n"
-
- text.strip
-end
-
# Add random words to the end of a license to test similarity tollerances
def add_random_words(string, count = 5)
- string = string.dup
- ipsum = %w[lorem ipsum dolor sit amet consectetur adipiscing elit]
+ words = string.dup.split(' ')
+ ipsum = File.read(fixture_path('ipsum.txt')).split(' ')
count.times do
- string << " #{ipsum[Random.rand(ipsum.length)]}"
+ word = ipsum[Random.rand(ipsum.length)]
+ index = Random.rand(words.length)
+ words.insert(index, word)
end
- string
+ words.join(' ')
end
# Init git dir
# Note: we disable gpgsign and restore it to its original setting to avoid
# Signing commits during tests and slowing down / breaking specs
@@ -83,28 +70,30 @@
match { |path| File.exist?(path) }
end
RSpec::Matchers.define :be_detected_as do |expected|
match do |actual|
- @expected_as_array = [expected.content]
- license_file = Licensee::Project::LicenseFile.new(actual, 'LICENSE')
+ @expected_as_array = [expected.content_normalized(wrap: 80)]
+ license_file = Licensee::ProjectFiles::LicenseFile.new(actual, 'LICENSE')
+ @actual = license_file.content_normalized(wrap: 80)
return false unless license_file.license
values_match? expected, license_file.license
end
failure_message do |actual|
- license_file = Licensee::Project::LicenseFile.new(actual, 'LICENSE')
+ license_file = Licensee::ProjectFiles::LicenseFile.new(actual, 'LICENSE')
license_name = expected.meta['spdx-id'] || expected.key
similarity = expected.similarity(license_file)
msg = "Expected the content to match the #{license_name} license"
msg << " (#{format_percent(similarity)} similarity"
msg << "using the #{license_file.matcher} matcher)"
end
failure_message_when_negated do |actual|
- license_file = Licensee::Project::LicenseFile.new(actual, 'LICENSE')
+ license_file = Licensee::ProjectFiles::LicenseFile.new(actual, 'LICENSE')
license_name = expected.meta['spdx-id'] || expected.key
similarity = expected.similarity(license_file)
+
msg = "Expected the content to *not* match the #{license_name} license"
msg << " (#{format_percent(similarity)} similarity)"
end
diffable