spec/licensee/content_helper_spec.rb in licensee-8.8.1 vs spec/licensee/content_helper_spec.rb in licensee-8.8.2

- old
+ new

@@ -1,26 +1,27 @@ class ContentHelperTestHelper include Licensee::ContentHelper attr_accessor :content - DEFAULT_CONTENT = <<-EOS.freeze + def initialize(content = nil) + @content = content + end +end + +RSpec.describe Licensee::ContentHelper do + let(:content) do + <<-EOS.freeze The MIT License Copyright 2016 Ben Balter The made up license. ----------- - EOS - - def initialize(content = nil) - @content = content || DEFAULT_CONTENT +EOS end -end - -RSpec.describe Licensee::ContentHelper do - subject { ContentHelperTestHelper.new } + subject { ContentHelperTestHelper.new(content) } let(:mit) { Licensee::License.find('mit') } it 'creates the wordset' do expect(subject.wordset).to eql(Set.new(%w(the made up license))) end @@ -72,17 +73,21 @@ expect(normalized_content).to_not match(/\n/) end 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 regex = /\A#{license.name_without_version}/i expect(license.content_normalized).to_not match(regex) + expect(stripped_content).to_not 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) end it 'strips the copyright' do expect(license.content_normalized).to_not match(/\Acopyright/i) end @@ -99,8 +104,26 @@ expect(normalized_content).to_not match('MIT') end it 'normalize the content' do expect(normalized_content).to eql 'the made up license.' + 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).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).to eql('foo') + end end end end