Sha256: e5167a2a2fb6e20e0e86a09ccb672e46861090e53aa20edf2f8d983346bf4342

Contents?: true

Size: 991 Bytes

Versions: 93

Compression:

Stored size: 991 Bytes

Contents

#! /usr/bin/env ruby

require 'facter/util/file_read'
require 'spec_helper'

describe Facter::Util::FileRead do
  let(:issue) { "Ubuntu 10.04.4 LTS \\n \\l\n\n" }

  it "reads a file" do
    File.expects(:read).with("/etc/issue").returns(issue)
    Facter::Util::FileRead.read("/etc/issue").should == issue
  end

  it "returns nil if the file cannot be accessed" do
    File.stubs(:read).with("/etc/issue").raises(Errno::EACCES.new("/etc/issue"))
    Facter::Util::FileRead.read("/etc/issue").should be_nil
  end

  it "returns nil if the file does not exist" do
    File.stubs(:read).with("/etc/issue").raises(Errno::ENOENT.new("/etc/issue"))
    Facter::Util::FileRead.read("/etc/issue").should be_nil
  end

  it "logs a message when handing exceptions" do
    File.stubs(:read).with("/etc/issue").raises(Errno::EACCES.new("/etc/issue"))
    Facter.expects(:debug).with("Could not read /etc/issue: Permission denied - /etc/issue")
    Facter::Util::FileRead.read("/etc/issue")
  end
end

Version data entries

93 entries across 93 versions & 1 rubygems

Version Path
facter-1.7.6 spec/unit/util/file_read_spec.rb
facter-2.0.2 spec/unit/util/file_read_spec.rb
facter-2.0.2-x86-mingw32 spec/unit/util/file_read_spec.rb
facter-2.0.2-universal-darwin spec/unit/util/file_read_spec.rb
facter-2.0.1 spec/unit/util/file_read_spec.rb
facter-2.0.1-x86-mingw32 spec/unit/util/file_read_spec.rb
facter-2.0.1-universal-darwin spec/unit/util/file_read_spec.rb
facter-2.0.1.rc4 spec/unit/util/file_read_spec.rb
facter-2.0.1.rc4-x86-mingw32 spec/unit/util/file_read_spec.rb
facter-2.0.1.rc4-universal-darwin spec/unit/util/file_read_spec.rb
facter-2.0.1.rc3 spec/unit/util/file_read_spec.rb
facter-2.0.1.rc3-x86-mingw32 spec/unit/util/file_read_spec.rb
facter-2.0.1.rc3-universal-darwin spec/unit/util/file_read_spec.rb
facter-2.0.1.rc2 spec/unit/util/file_read_spec.rb
facter-2.0.1.rc2-x86-mingw32 spec/unit/util/file_read_spec.rb
facter-2.0.1.rc2-universal-darwin spec/unit/util/file_read_spec.rb
facter-2.0.1.rc1 spec/unit/util/file_read_spec.rb
facter-2.0.1.rc1-x86-mingw32 spec/unit/util/file_read_spec.rb
facter-2.0.1.rc1-universal-darwin spec/unit/util/file_read_spec.rb
facter-1.7.5 spec/unit/util/file_read_spec.rb