Created
March 29, 2013 19:44
-
-
Save bttf/5273122 to your computer and use it in GitHub Desktop.
file_join_patch.rb fixes an issue with ruby's file join implementation which blows up if non-UTF-8 encoding gets passed in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class File | |
class << self | |
alias_method :original_join, :join | |
end | |
def self.join(*args) | |
new_args = args.collect { |questionableEncoding| | |
join_encoding_fix(questionableEncoding) | |
} | |
self.send(:original_join, new_args) | |
end | |
def self.join_encoding_fix(value) | |
if (value.instance_of?(String)) | |
value = self.convert(value) | |
elsif (value.instance_of?(Array)) | |
value = value.collect { |subValue| | |
join_encoding_fix(subValue) | |
} | |
end | |
value | |
end | |
# | |
# Ruby 1.8.7 requires the iconv library for string encoding | |
# Ruby 1.9.3 uses the default encode method on string. | |
# | |
def self.convert(value) | |
if value.respond_to? :encode | |
value.encode("UTF-8") | |
else | |
require 'iconv' | |
iconv = Iconv.new('ISO-8859-1', 'utf-8') | |
iconv.iconv(value) | |
end | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
F | |
Failures: | |
1) puppetmaster when applied to any old node | |
Failure/Error: }) | |
Puppet::Error: | |
Could not find class puppetmaster for 88nn7w1.mustard.com on node 88nn7w1.mustard.com | |
# ./spec/classes/puppetmaster_spec.rb:9:in `block (3 levels) in <top (required)>' | |
Finished in 0.083 seconds | |
1 example, 1 failure | |
Failed examples: | |
rspec ./spec/classes/puppetmaster_spec.rb:6 # puppetmaster when applied to any old node | |
C:/ruby193/bin/ruby.exe -S rspec spec/classes/puppetmaster_spec.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
require 'file_join_patch.rb' | |
describe 'puppetmaster', :type => :class do | |
describe 'when applied to any old node' do | |
it { | |
should contain_package('puppetmaster').with({ | |
'ensure' => 'present', | |
}) | |
should contain_service('puppetmaster').with({ | |
'ensure' => 'running', | |
}) | |
should contain_file('site_pp').with({ | |
'ensure' => 'file', | |
'path' => '/etc/puppet/manifests/site.pp', | |
'owner' => 'puppet', | |
'group' => 'puppet', | |
}) | |
should contain_file('puppet_conf').with({ | |
'ensure' => 'file', | |
'path' => '/etc/puppet/puppet.conf', | |
'owner' => 'puppet', | |
'group' => 'puppet', | |
}) | |
should contain_file('autosign_conf').with({ | |
'ensure' => 'file', | |
'path' => '/etc/puppet/autosign.conf', | |
'owner' => 'puppet', | |
'group' => 'puppet', | |
}) | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment