spec/licensee/content_helper_spec.rb in licensee-8.9.2 vs spec/licensee/content_helper_spec.rb in licensee-9.0.0.beta.1

- old
+ new

@@ -9,15 +9,17 @@ RSpec.describe Licensee::ContentHelper do let(:content) do <<-EOS.freeze.gsub(/^\s*/, '') # The MIT License - ================= + ================= - Copyright 2016 Ben Balter + Copyright 2016 Ben Balter + ************************* The made + * * * * up license. ----------- EOS end subject { ContentHelperTestHelper.new(content) } @@ -29,19 +31,15 @@ it 'knows the length' do expect(subject.length).to eql(20) end - it 'knows the max delta' do - expect(subject.max_delta).to eql(1) - end - context 'a very long license' do let(:content) { 'license' * 1000 } - it 'does not return a max delta larger than 150' do - expect(subject.max_delta).to eql(150) + it 'returns the max delta' do + expect(subject.max_delta).to eql(140) end end it 'knows the length delta' do expect(subject.length_delta(mit)).to eql(1000) @@ -52,13 +50,25 @@ expect(subject.similarity(mit)).to be_within(1).of(2) expect(subject.similarity(subject)).to eql(100.0) end it 'calculates the hash' do - expect(subject.hash).to eql('3c59634b9fae4396a76a978f3f6aa718ed790a9a') + content_hash = '3c59634b9fae4396a76a978f3f6aa718ed790a9a' + expect(subject.content_hash).to eql(content_hash) end + it 'wraps' do + content = Licensee::ContentHelper.wrap(mit.content, 40) + lines = content.split("\n") + expect(lines.first.length).to be <= 40 + end + + it 'formats percents' do + percent = Licensee::ContentHelper.format_percent(12.3456789) + expect(percent).to eql('12.35%') + end + context 'normalizing' do let(:normalized_content) { subject.content_normalized } it 'strips copyright' do expect(normalized_content).to_not match 'Copyright' @@ -70,17 +80,31 @@ expect(normalized_content).to match 'the' end it 'strips HRs' do expect(normalized_content).to_not match '---' + expect(normalized_content).to_not match '===' + expect(normalized_content).to_not include '***' + expect(normalized_content).to_not include '* *' end + it 'strips formatting from the MPL' do + license = Licensee::License.find('mpl-2.0') + expect(license.content_normalized).to_not include('* *') + end + + it 'wraps' do + lines = mit.content_normalized(wrap: 40).split("\n") + expect(lines.first.length).to be <= 40 + end + it 'squeezes whitespace' do expect(normalized_content).to_not match ' ' end it 'strips whitespace' do expect(normalized_content).to_not match(/\n/) + expect(normalized_content).to_not match(/\t/) end it 'strips markdown headings' do expect(normalized_content).to_not match('#') end