diff --git a/lib/nanoc/base/entities/identifier.rb b/lib/nanoc/base/entities/identifier.rb index 54230e56a7..6e4f5e1ac2 100644 --- a/lib/nanoc/base/entities/identifier.rb +++ b/lib/nanoc/base/entities/identifier.rb @@ -106,37 +106,20 @@ def prefix(string) end # @return [String] - def with_ext(ext) + def without_ext unless full? raise UnsupportedLegacyOperationError end - # Strip extension, if any extname = File.extname(@string) - string = - if extname.size > 0 - @string[0..-extname.size - 1] - else - @string - end - # Add extension - if ext.size > 0 - if ext.start_with?('.') - string + ext - else - string + '.' + ext - end + if extname.size > 0 + @string[0..-extname.size - 1] else - string + @string end end - # @return [String] - def without_ext - with_ext('') - end - # @return [String] The extension, without a leading dot. def ext unless full? diff --git a/spec/nanoc/base/entities/identifier_spec.rb b/spec/nanoc/base/entities/identifier_spec.rb index 362ec0f282..f0db409106 100644 --- a/spec/nanoc/base/entities/identifier_spec.rb +++ b/spec/nanoc/base/entities/identifier_spec.rb @@ -242,75 +242,6 @@ end end - describe '#with_ext' do - subject { identifier.with_ext(ext) } - - context 'legacy type' do - let(:identifier) { described_class.new('/foo/', type: :legacy) } - let(:ext) { 'html' } - - it 'raises an error' do - expect { subject }.to raise_error(Nanoc::Identifier::UnsupportedLegacyOperationError) - end - end - - context 'identifier with no extension' do - let(:identifier) { described_class.new('/foo') } - - context 'extension without dot given' do - let(:ext) { 'html' } - - it 'adds an extension' do - expect(subject).to eql('/foo.html') - end - end - - context 'extension with dot given' do - let(:ext) { '.html' } - - it 'adds an extension' do - expect(subject).to eql('/foo.html') - end - end - - context 'empty extension given' do - let(:ext) { '' } - - it 'removes the extension' do - expect(subject).to eql('/foo') - end - end - end - - context 'identifier with extension' do - let(:identifier) { described_class.new('/foo.md') } - - context 'extension without dot given' do - let(:ext) { 'html' } - - it 'adds an extension' do - expect(subject).to eql('/foo.html') - end - end - - context 'extension with dot given' do - let(:ext) { '.html' } - - it 'adds an extension' do - expect(subject).to eql('/foo.html') - end - end - - context 'empty extension given' do - let(:ext) { '' } - - it 'removes the extension' do - expect(subject).to eql('/foo') - end - end - end - end - describe '#without_ext' do subject { identifier.without_ext }