Sha256: 545b9620fa89582f149742c03ee08b6ea7984ceddbf2b6c0fade12a7203fdbfa

Contents?: true

Size: 1.09 KB

Versions: 18

Compression:

Stored size: 1.09 KB

Contents

require 'spec_helper'

describe Puppet::FileSystem::Tempfile do
  it "makes the name of the file available" do
    Puppet::FileSystem::Tempfile.open('foo') do |file|
      expect(file.path).to match(/foo/)
    end
  end

  it "provides a writeable file" do
    Puppet::FileSystem::Tempfile.open('foo') do |file|
      file.write("stuff")
      file.flush

      expect(Puppet::FileSystem.read(file.path)).to eq("stuff")
    end
  end

  it "returns the value of the block" do
    the_value = Puppet::FileSystem::Tempfile.open('foo') do |file|
      "my value"
    end

    expect(the_value).to eq("my value")
  end

  it "unlinks the temporary file" do
    filename = Puppet::FileSystem::Tempfile.open('foo') do |file|
      file.path
    end

    expect(Puppet::FileSystem.exist?(filename)).to be_false
  end

  it "unlinks the temporary file even if the block raises an error" do
    filename = nil

    begin
      Puppet::FileSystem::Tempfile.open('foo') do |file|
        filename = file.path
        raise "error!"
      end
    rescue
    end

    expect(Puppet::FileSystem.exist?(filename)).to be_false
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
puppet-3.6.2 spec/unit/file_system/tempfile_spec.rb
puppet-3.6.2-x86-mingw32 spec/unit/file_system/tempfile_spec.rb
puppet-3.6.1 spec/unit/file_system/tempfile_spec.rb
puppet-3.6.1-x86-mingw32 spec/unit/file_system/tempfile_spec.rb
puppet-3.6.0 spec/unit/file_system/tempfile_spec.rb
puppet-3.6.0-x86-mingw32 spec/unit/file_system/tempfile_spec.rb
puppet-3.6.0.rc1 spec/unit/file_system/tempfile_spec.rb
puppet-3.6.0.rc1-x86-mingw32 spec/unit/file_system/tempfile_spec.rb
puppet-3.5.1 spec/unit/file_system/tempfile_spec.rb
puppet-3.5.1-x86-mingw32 spec/unit/file_system/tempfile_spec.rb
puppet-3.5.1.rc1 spec/unit/file_system/tempfile_spec.rb
puppet-3.5.1.rc1-x86-mingw32 spec/unit/file_system/tempfile_spec.rb
puppet-3.5.0.rc3 spec/unit/file_system/tempfile_spec.rb
puppet-3.5.0.rc3-x86-mingw32 spec/unit/file_system/tempfile_spec.rb
puppet-3.5.0.rc2 spec/unit/file_system/tempfile_spec.rb
puppet-3.5.0.rc2-x86-mingw32 spec/unit/file_system/tempfile_spec.rb
puppet-3.5.0.rc1 spec/unit/file_system/tempfile_spec.rb
puppet-3.5.0.rc1-x86-mingw32 spec/unit/file_system/tempfile_spec.rb