spec/licensee/content_helper_spec.rb in licensee-9.12.0 vs spec/licensee/content_helper_spec.rb in licensee-9.13.0

- old
+ new

@@ -13,10 +13,12 @@ @data[:filename] end end RSpec.describe Licensee::ContentHelper do + subject { ContentHelperTestHelper.new(content, filename: filename) } + let(:content) do <<-LICENSE.gsub(/^\s*/, '') # The MIT License ================= @@ -33,11 +35,11 @@ implementing the license's "software". ----------- LICENSE end let(:filename) { 'license.md' } - subject { ContentHelperTestHelper.new(content, filename: filename) } + let(:mit) { Licensee::License.find('mit') } let(:normalized_content) { subject.content_normalized } it 'creates the wordset' do wordset = Set.new( @@ -48,48 +50,48 @@ ) expect(subject.wordset).to eql(wordset) end it 'knows the length' do - expect(subject.length).to eql(135) + expect(subject.length).to be(135) end context 'a very long license' do let(:content) { 'license' * 1000 } it 'returns the max delta' do - expect(subject.max_delta).to eql(140) + expect(subject.max_delta).to be(140) end end it 'knows the length delta' do - expect(subject.length_delta(mit)).to eql(885) - expect(subject.length_delta(subject)).to eql(0) + expect(subject.length_delta(mit)).to be(885) + expect(subject.length_delta(subject)).to be(0) end it 'knows the similarity' do expect(subject.similarity(mit)).to be_within(1).of(11) - expect(subject.similarity(subject)).to eql(100.0) + expect(subject.similarity(subject)).to be(100.0) end it 'calculates the hash' do content_hash = '916b978940ecf8070c96bd3aca9321768e7f4901' expect(subject.content_hash).to eql(content_hash) end it 'wraps' do - content = Licensee::ContentHelper.wrap(mit.content, 40) + content = described_class.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) + percent = described_class.format_percent(12.3456789) expect(percent).to eql('12.35%') end - context '#strip' do + describe '#strip' do { version: "The MIT License\nVersion 1.0\nfoo", hrs: "The MIT License\n=====\n-----\n*******\nfoo", markdown_headings: "# The MIT License\n\nfoo", whitespace: "The MIT License\n\n foo ", @@ -100,11 +102,12 @@ title: "The MIT License\nfoo", copyright: "The MIT License\nCopyright 2018 Ben Balter\nFoo", end_of_terms: "Foo\nend of terms and conditions\nbar", block_markup: '> Foo', link_markup: '[Foo](http://exmaple.com)', - comment_markup: "/*\n* The MIT License\n* Foo\n*/" + comment_markup: "/*\n* The MIT License\n* Foo\n*/", + copyright_title: "Copyright 2019 Ben Balter\nMIT License\nFoo" }.each do |field, fixture| context "#strip_#{field}" do let(:content) { fixture } it "strips #{field}" do @@ -131,49 +134,49 @@ end end context 'integration fixture' do it 'strips copyright' do - expect(normalized_content).to_not match 'Copyright' - expect(normalized_content).to_not match 'Ben Balter' + expect(normalized_content).not_to match 'Copyright' + expect(normalized_content).not_to match 'Ben Balter' end it 'downcases' do - expect(normalized_content).to_not match 'The' + expect(normalized_content).not_to match 'The' 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 '* *' + expect(normalized_content).not_to match '---' + expect(normalized_content).not_to match '===' + expect(normalized_content).not_to include '***' + expect(normalized_content).not_to include '* *' end it 'squeezes whitespace' do - expect(normalized_content).to_not match ' ' + expect(normalized_content).not_to match ' ' end it 'strips whitespace' do - expect(normalized_content).to_not match(/\n/) - expect(normalized_content).to_not match(/\t/) + expect(normalized_content).not_to match(/\n/) + expect(normalized_content).not_to match(/\t/) end it 'strips markdown headings' do - expect(normalized_content).to_not match('#') + expect(normalized_content).not_to match('#') end it 'strips all rights reserved' do - expect(normalized_content).to_not match(/all rights reserved/i) + expect(normalized_content).not_to match(/all rights reserved/i) end it 'strips markup' do - expect(normalized_content).to_not match(/[*=_-]+/) + expect(normalized_content).not_to match(/[*=_-]+/) end it 'normalizes quotes' do - expect(normalized_content).to_not match("'as is'") + expect(normalized_content).not_to match("'as is'") end it 'preserves possessives' do expect(normalized_content).to match("contributors'") expect(normalized_content).to match("license's") @@ -182,11 +185,11 @@ it 'preserves double quotes' do expect(normalized_content).to match('"software"') end it 'strips the title' do - expect(normalized_content).to_not match('MIT') + expect(normalized_content).not_to match('MIT') end it 'normalize the content' do expected = 'the made up license. this license provided "as is". '.dup expected << "please respect the contributors' wishes when implementing " @@ -236,17 +239,17 @@ end end it 'strips formatting from the MPL' do license = Licensee::License.find('mpl-2.0') - expect(license.content_normalized).to_not include('* *') + expect(license.content_normalized).not_to include('* *') end it 'normalizes http: to https:' do license = Licensee::License.find('mpl-2.0') expect(license.content).to include('http:') - expect(license.content_normalized).to_not include('http:') + expect(license.content_normalized).not_to include('http:') end it 'wraps' do lines = mit.content_normalized(wrap: 40).split("\n") expect(lines.first.length).to be <= 40 @@ -263,53 +266,51 @@ Licensee::License.all(hidden: true).each do |license| context license.name do let(:stripped_content) { subject.content_without_title_and_version } it 'strips the title' do - skip "Doesn't strip ECL title" if license.key == 'ecl-2.0' - regex = Licensee::License::ALT_TITLE_REGEX[license.key] - regex ||= /\A#{license.name_without_version}/i - expect(stripped_content).to_not match(regex) - expect(license.content_normalized).to_not match(regex) + regex = /\A#{license.name_without_version}/i + expect(stripped_content).not_to match(regex) + expect(license.content_normalized).not_to match(regex) end it 'strips the version' do - expect(license.content_normalized).to_not match(/\Aversion/i) - expect(stripped_content).to_not match(/\Aversion/i) + expect(license.content_normalized).not_to match(/\Aversion/i) + expect(stripped_content).not_to match(/\Aversion/i) end it 'strips all rights reserved' do regex = /all rights reserved/i - expect(license.content_normalized).to_not match(regex) + expect(license.content_normalized).not_to match(regex) end it 'strips the copyright' do - expect(license.content_normalized).to_not match(/\Acopyright/i) + expect(license.content_normalized).not_to match(/\Acopyright/i) end it 'strips the implementation instructions' do end_terms_regex = /END OF TERMS AND CONDITIONS/i - expect(license.content_normalized).to_not match(end_terms_regex) - expect(license.content_normalized).to_not match(/How to apply/i) + expect(license.content_normalized).not_to match(end_terms_regex) + expect(license.content_normalized).not_to match(/How to apply/i) end end end context 'a title in parenthesis' do let(:content) { "(The MIT License)\n\nfoo" } it 'strips the title' do - expect(normalized_content).to_not match('MIT') + expect(normalized_content).not_to match('MIT') expect(normalized_content).to eql('foo') end end context 'multiple copyrights' do let(:content) { "Copyright 2016 Ben Balter\nCopyright 2017 Bob\nFoo" } it 'strips multiple copyrights' do - expect(normalized_content).to_not match('Ben') + expect(normalized_content).not_to match('Ben') expect(normalized_content).to eql('foo') end end end @@ -359,20 +360,20 @@ context 'escaping' do let(:text) { 'gpl-3 0' } it 'escapes' do - expect(text).to_not match(described_class.title_regex) + expect(text).not_to match(described_class.title_regex) end end context 'in the middle of a string' do let(:text) do "The project is not licensed under the #{license_variation} license" end it 'matches' do - expect(text).to_not match(described_class.title_regex) + expect(text).not_to match(described_class.title_regex) end end end end end