Sha256: 9338c42063221d686b92b6b16585ffbd10230077c8ded73c215e4d894e0af12e

Contents?: true

Size: 1.68 KB

Versions: 33

Compression:

Stored size: 1.68 KB

Contents

describe Nanoc::Int::TempFilenameFactory do
  subject do
    Nanoc::Int::TempFilenameFactory.new
  end

  let(:prefix) { 'foo' }

  describe '#create' do
    it 'should create unique paths' do
      path_a = subject.create(prefix)
      path_b = subject.create(prefix)
      path_a.wont_equal(path_b)
    end

    it 'should return absolute paths' do
      path = subject.create(prefix)
      path.must_match(/\A\//)
    end

    it 'should create the containing directory' do
      Dir[subject.root_dir + '/**/*'].must_equal([])
      path = subject.create(prefix)
      File.directory?(File.dirname(path)).must_equal(true)
    end

    it 'should reuse the same path after cleanup' do
      path_a = subject.create(prefix)
      subject.cleanup(prefix)
      path_b = subject.create(prefix)
      path_a.must_equal(path_b)
    end
  end

  describe '#cleanup' do
    it 'should remove generated files' do
      path_a = subject.create(prefix)
      File.file?(path_a).wont_equal(true) # not yet used

      File.open(path_a, 'w') { |io| io << 'hi!' }
      File.file?(path_a).must_equal(true)

      subject.cleanup(prefix)
      File.file?(path_a).wont_equal(true)
    end

    it 'should eventually delete the root directory' do
      subject.create(prefix)
      File.directory?(subject.root_dir).must_equal(true)

      subject.cleanup(prefix)
      File.directory?(subject.root_dir).wont_equal(true)
    end
  end

  describe 'other instance' do
    let(:other_instance) do
      Nanoc::Int::TempFilenameFactory.new
    end

    it 'should create unique paths across instances' do
      path_a = subject.create(prefix)
      path_b = other_instance.create(prefix)
      path_a.wont_equal(path_b)
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
nanoc-4.3.7 test/base/temp_filename_factory_spec.rb
nanoc-4.3.6 test/base/temp_filename_factory_spec.rb
nanoc-4.3.5 test/base/temp_filename_factory_spec.rb
nanoc-4.3.4 test/base/temp_filename_factory_spec.rb
nanoc-4.3.3 test/base/temp_filename_factory_spec.rb
nanoc-4.3.2 test/base/temp_filename_factory_spec.rb
nanoc-4.3.1 test/base/temp_filename_factory_spec.rb
nanoc-4.3.0 test/base/temp_filename_factory_spec.rb
nanoc-4.2.4 test/base/temp_filename_factory_spec.rb
nanoc-4.2.3 test/base/temp_filename_factory_spec.rb
nanoc-4.2.2 test/base/temp_filename_factory_spec.rb
nanoc-4.2.1 test/base/temp_filename_factory_spec.rb
nanoc-4.2.0 test/base/temp_filename_factory_spec.rb
nanoc-4.1.6 test/base/temp_filename_factory_spec.rb
nanoc-4.2.0b1 test/base/temp_filename_factory_spec.rb
nanoc-4.1.5 test/base/temp_filename_factory_spec.rb
nanoc-4.1.4 test/base/temp_filename_factory_spec.rb
nanoc-4.1.3 test/base/temp_filename_factory_spec.rb
nanoc-4.1.2 test/base/temp_filename_factory_spec.rb
nanoc-4.1.1 test/base/temp_filename_factory_spec.rb