fakeetc
A fake Ruby Etc
module for your tests.
Intended as a drop-in replacement for Etc in unit tests.
Usage
require 'fakeetc'
FakeEtc.add_groups({
'empty' => { gid: 42, mem: [] },
'anonymous' => { gid: 43, mem: ['johndoe'] }
})
FakeEtc.add_users({
'janedoe' => { uid: 10,
gid: 20,
gecos: 'Jane Doe',
dir: '/home/janedoe',
shell: '/bin/zsh' },
'jackdoe' => { uid: 50,
gid: 60,
gecos: 'Jack Doe',
dir: '/home/jackdoe',
shell: '/bin/bash' },
})
anonymous = nil
jack = nil
FakeEtc do
anonymous = Etc.getgrnam('anonymous')
jack = Etc.getpwuid(50)
end
anonymous
# => #<struct Struct::Group
# name="anonymous",
# passwd="x",
# gid=43,
# mem=["johndoe"]>
jack
# => #<struct Struct::Passwd
# name="jackdoe",
# passwd="x",
# uid=50,
# gid=60,
# gecos="Jack Doe",
# dir="/home/jackdoe",
# shell="/bin/bash",
# change=nil,
# uclass=nil,
# expire=nil>
Copyright
Copyright (c) 2015 Sebastian Boehm. See LICENSE for details.