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-2.5.7 spec/unit/util/file_read_spec.rb
facter-2.5.7-x86-mingw32 spec/unit/util/file_read_spec.rb
facter-2.5.7-x64-mingw32 spec/unit/util/file_read_spec.rb
facter-2.5.7-universal-darwin spec/unit/util/file_read_spec.rb
facter-2.5.6-x86-mingw32 spec/unit/util/file_read_spec.rb
facter-2.5.6-x64-mingw32 spec/unit/util/file_read_spec.rb
facter-2.5.6-universal-darwin spec/unit/util/file_read_spec.rb
facter-2.5.6 spec/unit/util/file_read_spec.rb
facter-2.5.5-x86-mingw32 spec/unit/util/file_read_spec.rb
facter-2.5.5-x64-mingw32 spec/unit/util/file_read_spec.rb
facter-2.5.5-universal-darwin spec/unit/util/file_read_spec.rb
facter-2.5.5 spec/unit/util/file_read_spec.rb
facter-2.5.4-x86-mingw32 spec/unit/util/file_read_spec.rb
facter-2.5.4-x64-mingw32 spec/unit/util/file_read_spec.rb
facter-2.5.4-universal-darwin spec/unit/util/file_read_spec.rb
facter-2.5.4 spec/unit/util/file_read_spec.rb
facter-2.5.1 spec/unit/util/file_read_spec.rb
facter-2.5.1-x86-mingw32 spec/unit/util/file_read_spec.rb
facter-2.5.1-x64-mingw32 spec/unit/util/file_read_spec.rb
facter-2.5.1-universal-darwin spec/unit/util/file_read_spec.rb