Hi,
Does someone knows more rspec code examples for working with files ?
I stumbled across https://github.com/puppetlabs/puppetlabs-inifile/blob/master/spec/unit/puppet/provider/ini_setting/ruby_spec.rb ,
but cannot find more examples, and struggling a bit in writing good rspec tests for the following code snippet :
(intention is to read the uid from a yaml file for users)
require 'yaml'
module Puppet::Parser::Functions
newfunction(:lookup_uid, :type => :rvalue ) do |args|
# read the configuration file from puppets configuration dir
configfile = File.join([File.dirname(Puppet.settings[:config]), 'lookup_uid.yaml'])
raise(Puppet::ParseError, "lookup_uid configfile not readable") unless File.exist?(configfile)
config = YAML.load_file(configfile)
# read the user yaml file
raise(Puppet::ParseError, "Could not load user mapping file (#{config['user_file']}") unless File.exists?(config['user_file'])
# Lookup the uid, and convert it to an integer
users = YAML.load_file(config['user_file'])
uid = users.fetch(args[0], ifnone = nil)
raise(Puppet::ParseError, "#{args[0]} user not found in #{config['user_file']}") unless uid
uid.to_int
end
end
Thxs
johan
--
Johan De Wit
Open Source Consultant
Red Hat Certified Engineer (805008667232363)
Puppet Certified Professional 2013/2014 (PCP0000006)
_________________________________________________________
Open-Future Phone +32 (0)2/255 70 70
Zavelstraat 72 Fax +32 (0)2/255 70 71
3071 KORTENBERG Mobile +32 (0)474/42 40 73
BELGIUM http://www.open-future.be
_________________________________________________________
Next Events:
Linux Training | https://www.open-future.be/linux-training-8-till-12th-september
Puppet Introduction Course | https://www.open-future.be/puppet-introduction-course-15th-september
Puppet Fundamentals Training | https://www.open-future.be/puppet-fundamentals-training-16-till-18th-september Zabbix Certified Specialist | https://www.open-future.be/zabbix-certified-specialisttraining-22-till-24th-september
Zabbix Certified Professional | https://www.open-future.be/zabbix-certified-professional-training-25-till-26th-september
Subscribe to our newsletter | http://eepurl.com/BUG8H
--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/53D248D8.9020304%40open-future.be.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/53D248D8.9020304%40open-future.be.
For more options, visit https://groups.google.com/d/optout.
--
Andrew Parker
Freenode: zaphod42Twitter: @aparker42Software Developer
Register by May 30th to take advantage of the Early Adopter discount —save $349!
--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/CANhgQXtapXGjYun92fLqkMZm%2B2OOVqdKpDDUpR5NQqj%2BroYRRA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
-- Johan De Wit Open Source Consultant Red Hat Certified Engineer (805008667232363) Puppet Certified Professional 2013/2014 (PCP0000006) _________________________________________________________ Open-Future Phone +32 (0)2/255 70 70
Zavelstraat 72 Fax +32 (0)2/255 70 71 3071 KORTENBERG Mobile +32 (0)474/42 40 73 BELGIUM http://www.open-future.be _________________________________________________________
Upcoming Events: